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"; // ------------------------------------------------------ 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); } }
Answer2. How to run this Script
- Go to [Tools] – [Script Editor].
- A script window opens.
- Paste the script in the script editor and hit the [Run] button – the right triangle one.
- The color is added to all the Execution Specifications.
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.
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.
Most tools capable of drawing UML sequence diagrams place an execution specification on both sides by default — why is that? — as is the case with Visual Paradigm
Hi. The notation is defined so in 17.2.4.4 ExecutionSpecification in Unified Modeling Language 2.5.1 published by OMG – https://www.omg.org/spec/UML/2.5.1/PDF .
> ExecutionSpecifications are represented as thin rectangles (gray or white) on the lifeline
But Astah has an option to remove the rectangles.
https://astah.net/support/astah-pro/user-guide/sequence-diagram/#hide-execution-specification