As a Business Analyst I’m finding it very useful to have multiple viewpoints of the same diagram whether to show the evolution of an Architecture from the AS-IS through multiple Transitional Stages to the TO-BE, or to focus on a particular path through a Business Process to discuss how a Business Scenario will be handled.
My favorite technique is to create a master diagram containing all the elements, copy that, and then gray-out the elements that are not part of the Business Scenario or Release under discussion. Unfortunately this can be very manually intensive if I need to make a change to the diagram.
My original hope was to have a single diagram and then use Diagram Filters which worked well for my Architecture Diagrams, allowing me to filter by Phase, and Status, but did not work well for Business Process diagrams or printed reports. So I decided to see if I could use Sparx EA’s API to make a script that would allow me to easily create and maintain the viewpoints.
- The User creates the master diagram that the viewpoints will be synced to.
- The User adds an element to the master diagram that will represent the viewpoint. For my Architecture diagrams (Archimate 2.0) I use a Plateau Element, for my Business Process Diagrams (Archimate + BPMN) I used a ToGAF Business Scenario Element.
- The User selects (in the master diagram) the viewpoint elements that they just added
- The User runs the Create Linked Diagrams (and sync) script.
- The User selects Yes when prompted (alternate the User selects No to only create a new linked diagram without syncing it)
- The System creates a new linked diagram (alternate, a linked diagram already exists)
- The System loops through all the elements and connectors in the master diagram and adds them to the new linked diagram (alternate, the System updates the positions existing matching elements, and removes any unmatched elements in the viewpoint)
- Once the script is completed, the User can open the newly created diagrams and apply whatever local styles you want to the Elements (I have a general “Ignore” style that grays-out the selected Elements and Connectors)
As mentioned in the alternate steps, if you need to make any changes to the master diagram, rerun the script. Any changes (removals, additions, movements) will then be reflected in the synced diagrams. Colours and fonts of Elements and Connectors in the viewpoint will NOT be modified.
Creating this Script
The object model for Diagrams in Sparx EA is:
- Diagram -> DiagramObject -> Element
- Diagram -> DiagramLink -> Connector
When I set out to create this script I thought it would be easy, simply loop through all the DiagramObjects and DiagramLinks in the master diagram, and create or update the matching objects in the synced viewpoints…. then I discovered some quirks for Sparx EA:
- You can’t create DiagramLinks through the API
- You can create DiagramObjects even though the documentation say’s the Diagram.DiagramObjects collection is readonly, but I couldn’t update them once they were created!?!
- The DiagramLink object for a connector is NOT created by default, it is only created if you manually move the connector in a diagram.
- The colour and formatting settings can be set on a per diagram basis, but are stored as name-value pairs as a list in a single property
- For Elements: DiagramObject.style for Elements
- For Connectors: DiagramLink.geometry, DiagramLink.path, DiagramLink.style
To address the first 3 quirks I ended up having to use the undocumented Repository.Execute function to create the DiagramLink objects that are missing (INSERT INTO t_diagramlinks …), and to update any Objects that exist (UPDATE t_diagramlinks …)
To address the 3rd quirk, I created an object to let me more easily manipulate these settings.
The next steps are:
- updating my
$Repository library(replaced by my EARecordset library on 2019-03-29) to support the general creation and modification of DiagramLinks and DiagramObjects, and
- creating a Wink video tutorial on how to use the script.