Coloring Execution specification in Sequence Diagram using Script

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

Recently, we’ve received the following question from our user, and I’d like to share the solution we provided to him.

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).


Answer1: Cannot set the default color

Default colors for most of the objects can be set in [Tool] – [System Properties] – [Default Item Color], however Execution Specification in Sequence Diagram isn’t one of them at the moment.


So we wrote a script to add colors to them that he can run using this [Script Editor].

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";
// ------------------------------------------------------


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

function getCurrentSequenceDiagram() {
        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)) {
        var model = presentation.getModel();
        if (model != null) {
        var parentPresentation = presentation.getParent();
        if (parentPresentation == null) {
    return executionSpecificationPresentations;

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

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

Answer2. How to run this Script

  1. Go to [Tools] – [Script Editor].

  3. A script window opens.

  5. Paste the script in the script editor and hit the [Run] button – the right triangle one.

  7. The color is added to all the Execution Specifications.

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

Let’s use more Scripts!

This Script Editor unleashes Astah’s ability. You can add any customized features using API and perform through this script editor. There are many sample scripts that you can copy and paste and use right away.

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

If you are using Astah Community

You can use this script editor by installing the Plug-in.  However, the API for Astah Community is limited to read-function only, so you cannot add/edit models. If you’d like to try out the whole capabilities, download the free trial of Astah Pro or UML.
astah-pro   astah-uml

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

Related links

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

2 thoughts on “Coloring Execution specification in Sequence Diagram using Script

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s