【スクリプトで簡単!】シーケンス図の実行仕様の色を一括で変更する

スクリーンショット 2019-05-22 14.08.40

先日、海外のお客様より「シーケンス図の実行仕様のデフォルト色を指定したい」というお問合せをいただきました。その回答内容を公開します。

Q: How do I set the default color for the lifeline activity?
I want to set this globally as well as per project. When I create a new activity, as seen below, the color of the activity is white (or no color).

 

A1. あいにく、デフォルト色は指定できません

図要素のデフォルト色は、[ツール] – [システムプロパティ] – [新規図要素の色]から指定できるものもありますが、シーケンス図の実行仕様に関しては、あいにく現在非対応で、ここには含まれていません。
sys-pro.png

かといって、実行仕様の色を一つ一つ変更していくのも大変ですので、、
color

お客様には、実行仕様の色を一括で変更できるスクリプトを作成してお渡ししました。
このスクリプトは、スクリプトエディタを使って実行できます。

var infNamespace = 'com.change_vision.jude.api.inf'
var ISequenceDiagram = Java.type(infNamespace + '.model.ISequenceDiagram');
var Key = Java.type(infNamespace + '.presentation.PresentationPropertyConstants.Key');
var INodePresentation = Java.type(infNamespace + '.presentation.INodePresentation');

// ------------------------------------------------------
// Please set the new color as you like.
var COLOR = "#fc3768";
// ------------------------------------------------------

run();

function run() {
var currentSequenceDiagram = getCurrentSequenceDiagram();
if (currentSequenceDiagram == null) {
print("error : Please open the sequence diagram.");
return;
}
var presentations = getPresentations(currentSequenceDiagram);
var chengeColorPresentations = getExecutionSpecificationPresentations(presentations);
setColor(chengeColorPresentations, COLOR);
}

function getCurrentSequenceDiagram() {
try{
var viewManager = astah.getViewManager();
var diagramViewManager = viewManager.getDiagramViewManager();
var currentDiagram = diagramViewManager.getCurrentDiagram();
if(currentDiagram instanceof ISequenceDiagram) {
return currentDiagram;
}
return null;
} catch(e) {
return null;
}
}

function getPresentations(currentDiagram) {
try {
return currentDiagram.getPresentations();
} catch (e) {
return new IPresentation[0];
}
}

function getExecutionSpecificationPresentations(presentations) {
var executionSpecificationPresentations = [];
for (var i in presentations) {
var presentation = presentations[i];
if (presentation == null || !(presentation instanceof INodePresentation)) {
continue;
}
var model = presentation.getModel();
if (model != null) {
continue;
}
var parentPresentation = presentation.getParent();
if (parentPresentation == null) {
continue;
}
executionSpecificationPresentations.push(presentation);
}
return executionSpecificationPresentations;
}

function setColor(presentations, color) {
try {
astah.getTransactionManager().beginTransaction();
for(var i in presentations) {
var presentation = presentations[i];
presentation.setProperty(Key.FILL_COLOR, color);
}
astah.getTransactionManager().endTransaction();
print("info: Changed the color of " + presentations.length + " elements.");
} catch (e) {
astah.getTransactionManager().abortTransaction();
print("error : Could not change element color.");
print(e);
}
}

スクリーンショット 2019-05-22 14.08.40

A2. スクリプトの使い方はこちら

  1. まず、[ツール]-[スクリプトエディタ]を選択します。
    script-editor.png
  2. スクリプトエディタが開きます。
    script-editor-window.png
  3. シーケンス図を開いて、エディタ上部にスクリプトを貼り付けて[実行]ボタン(右三角)を押します。
    sequence-color
  4. 実行仕様が、指定色に変わります。
    done.png

スクリーンショット 2019-05-22 14.08.40

スクリプトを使ってみよう!

スクリプトエディタを使えば、このような図上編集はもちろん、特定のモデルデータを抽出したり、図上のノートを全て非表示にする、など、標準搭載されていない様々な機能をAPIを使って実行することができます。
コピー&ペーストしてすぐに使えるサンプルスクリプト集もあるので、ぜひお試しください。
※スクリプトエディタは、astah* pro・UML7.2で追加された機能ですが、これより古いバージョンや、astah* SysML・GSNをお使いの方は、プラグインとしてインストールする事で利用が可能になります。

 

編集APIを試したい方は、astah* professional、astah* UMLの無償評価版をぜひご利用ください。
astah-pro   astah-uml

スクリーンショット 2019-05-22 14.08.40

便利なリンク集

スクリーンショット 2019-05-22 14.08.40

みなさま、ぜひご活用ください! 🙂

コメントを残す

以下に詳細を記入するか、アイコンをクリックしてログインしてください。

WordPress.com ロゴ

WordPress.com アカウントを使ってコメントしています。 ログアウト /  変更 )

Twitter 画像

Twitter アカウントを使ってコメントしています。 ログアウト /  変更 )

Facebook の写真

Facebook アカウントを使ってコメントしています。 ログアウト /  変更 )

%s と連携中