gobravedave / Enterprise-Architect

scripts and other code snippets to extend Sparxs Enterprise Architect
BSD 2-Clause "Simplified" License
51 stars 12 forks source link

:toc: :icons: image :iconsdir: images :imagesdir: images //:numbered: = README

== Enterprise Architect Sripting

https://plantuml.com/[PlantUML] is awesome; it is accessible, easy to use and you produce nice looking diagrams with minimal effort in a short period of time. The PlantUML script can be published and made available for collaboration.

The problem however it that the PlantUML script used to generate the diagrams are discrete declarations of behaviour. Validation and alignment against the Domain and or Enterprise landscape would typically be manual and the likely outcome would be model divergence.

The cost savings from the speedy delivery of fit for purpose models is long forgotten when the time comes to make changes.

I do believe there is a middle ground where Enterprise and Delivery teams operating at differing speeds can effectively work together. The solution centres around the ability to exchange models between the modelling platform and the script based diagraming tools.

Enterprise Architect does offer a number of methods for model exchange. The simplest being CSV imports, for high order elements, through to XMI import/export for full element, association and diagrams objects.

PlantUML does support XMI export, however at this point it only applies to Class diagrams.

So one solution to close this gap, I have cobbled together a VBScript to run within Enterprise Architect to allow a modeller to Generate a Sequence Diagram using a PlantUML script.

=== Create a Sequence Diagram in EA using PlantUML

The following screen shot provide an example of what functionality is offered by the scripts.

The following steps outline the process of creating the sequence diagram within Enterprise Architect:

. create a new sequence diagram . add a note element and paste the desired plantUML script into it . right click the Note element and select Run PlantUML Script the following diagram is created

.Sample Generated Sequence Diagram image:xxxx-sequence-diagram.png[Enterprise Architect Sample]

NOTE: EA’s does have some restrictions on the way the flows can be laid out using the GUI.. and this is especially evident when using nested InteractionFragments. So please check the produced diagram to ensure correct flow placement.

=== Create a C4 Container Diagram in EA using PlantUML

The https://c4model.com/[C4 Model] is a lean graphical notation technique for modelling the architecture of software systems.

Sparxsystem provides a free https://www.sparxsystems.eu/c4[C4 MDG download] which defined the C4 shape toolbox and associated diagrams.

.Sample C4 Diagram using the LieberLieber C4 MDG image:C4 in EA.png[Sample C4 Diagram]

But wait.. What if you already had your context or container view in plantuml script form. There is no way that you will want to maintain 2 versions of the same document.

Say I had the following script.. how long would it take to manually produce the diagram in EA.


@startuml !include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Container.puml '!include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Dynamic.puml

' uncomment the following line and comment the first to use locally ' !include C4_Container.puml

'LAYOUT_TOP_DOWN() 'LAYOUT_AS_SKETCH() 'LAYOUT_WITH_LEGEND()

title C4 Container View via script

AddElementTag("Service", $shape=EightSidedShape(), $bgColor='Lightblue',$legendText='service (eight sided)')

AddRelTag(Alert, $textColor="red", $lineColor="red", $lineStyle = DashedLine(), $legendText="console triggered") AddRelTag(Synchronous, $textColor="black", $lineColor="dimgrey",$legendText="Synchronous") AddRelTag(Asynchronous,$textColor="black", $lineColor="dimgrey", $lineStyle = DashedLine(), $legendText="Asynchronous")

Container_Boundary(boundary, boundary){ Container(Container1, "Container one", "Application") Container_Boundary(boundary2, boundary2){ Container(Container3, "Container three","service", $tags='Service', "description") ContainerDb_Ext(Container4, "Container four","storage", "desc") Container(Container5, "Container five","Application", "container 5 description") Container(Container6, "Container six","Application", "container 6 description") } } ContainerDb_Ext(Container2, "Container two","storage", "desc")

Rel(Container1,Container3,"blah","Synchronous", $tags=Synchronous) Rel(Container1,Container5,"blah5","Synchronous", $tags=Synchronous) Rel(Container1,Container6,"blah6","Synchronous", $tags=Synchronous) Rel_R(Container3,Container4,"blah2","Alert", $tags=Alert) Rel(Container3,Container2,"","Asynchronous", $tags=Asynchronous) SHOW_LEGEND() @enduml

The following steps outline the process of creating the C4 diagram within Enterprise Architect:

. create a new C4 diagram . add a note element and paste the desired plantUML script into it . right click the Note element and select Run PlantUML Script the following diagram is created

.Sample C4 Container Diagram via the Run PlantUML Script image:Run PlantUML script output.png[Sample C4 Diagram]

Some limitations/half baked functionality..

=== Create a PlantUML Script from a Sequence or C4 Diagram In Enterprise Architecht

Model Management however is not just about being able to import sequence diagrams. The use case may exist in your organisation where diagrams require to be validated against some Enterprise standards, checking for duplicates within the model, for duplication against an Application Portfolio, naming standards, organisational context; all metadata which extends beyond the basic sequence diagram which has been described.

Hence these diagrams and/or the underlying modelling elements may well be updated within Modelling environment and there is a need to refresh one or more PlantUML scripts.

The following steps outline the process of creating PlantUML script from a sequence diagram within EA:

. open up an existing sequence diagram . add a note element to the sequence diagram . right click the Note element and select Create PlantUML script . the script will parse the diagram objects and links with the results loaded into the note object.

The above steps also apply to C4 Diagrams.

.Sample Generated Generation of PlantUML Script image:generatePlantUMLscript.gif[]]

This script preceded the import script and was the basis of discovering where various information about the diagram and underlying modelling objects are stored within EA.

=== Color Picker

Within PlantUML you are able to assign colors to an object or connector by using the the following values:

.:PlantUML Color Pallete image:plantuml-colors.png[]

Managing colors in EA is quite a complex topic. Each element type has a default color and it is also possible to apply default colors based on stereotype (via UML type setting or MDG UML Profile) or via shape scripts and driven possibly by a tagged value.

A modeller can override a default cold via the GUI using color palette.

Behind the scenes, Enterprise Architect will store the value of -1 if a default color is to be applied. If the default has been updated by the modeller, then the value is a decimal representation of the Blue Green Red components of the color is stored.

Hence the need to have a sub routine to allow a PlantUML color code to be converted into the decimal equivalent to be applied to an EA modelling element during the Create Sequence Diagram script.

Likewise when Generating the PlantUML script there is a requirement to take the decimal version and output the #colorname or #rrggbb value.

The common functions available are:

=== Backlog Items

The following features will be added overtime.

=== Installation Instructions

All scripts are included in the link:MyModel.EAP[MyModel.EAP] within this github repo.

Which were created using the following rather manual method:

Activate the the script manager window with EA

. Create a new Diagram Scripting Group and load it up with:

.EA Script Maanger image:EAscriptManager.jpg[EA Script MAanger]

[NOTE]

This Scripting facility is available in the Corporate, Unified and Ultimate editions.

If you intend to use the Scripting facility under Crossover/WINE, you must also install Internet Explorer version 6.0 or above.

Script names are case sensitive.

===============================