Thursday, 30 June 2016 03:19

Presenting the new open source Enterprise Architect Shapescript Library

Written by
Rate this item
(2 votes)
Github shapescript library

The new open source Enterprise Architect Shapescript Library in Github is an initiative to share shapescripts for Enterprise Architect within the user community.

Shapescripts in Enterprise Architect are used to define the presentation of elements on a diagram. They are mostly used when defining a UML profile in Enterprise Architect that extends UML or another modelling language with project specific elements and properties.

Shapescript examples

When developing UML profiles these shapescripts are stored in the _image attribute on the stereotype element, and they can be easily edited using the profile helper.

Shapescript editor

After a while however you’ll have a bunch of shapescripts scattered over different profiles, and projects, and it becomes hard to manage, or do any kind of version control. Finding a specific shapescript where you used a particular feature is next to impossible if you don’t remember exactly which stereotype this shapescript belonged to.

Exporting shapescripts

With the shapescript editor you can export each shapescript individually, but once you have more then a couple of shapescripts that quickly becomes a drag to save your shapescripts to files.

So I wrote a script called ExportAllShapeScripts that searches a repository for all stereotypes that have a shapescript, and exports all of these shapescripts in one go.

This script is part of the Enterprise-Architect-VBScript-Library. Read the article How to use the Enterprise Architect VBScript Library for instructions on downloading and using the Library in Enterprise Architect.

Running this script will save each shapescript as a textfile with extension .shapeScript, grouped in packages per profile.

Shapescripts saved

The code explained

The export script first uses an SQL query to find all shapescripts. Technically the shapescripts are stored in the default property of the attribute with the name _image. The script is stored as an xml tag Image in a zipped and base64 encoded format. A typical shapescript might look like this in the database:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<Image type="EAShapeScript 1.0" xmlns:dt="urn:schemas-microsoft-com:datatypes" dt:dt="bin.base64">
UEsDBBQAAAAIABpRIkdk2qflMQIAADIHAAAHABEAc3RyLmRhdFVUDQAHncrmVZ3K5lWdyuZV
jVXJTsMwFJxrkfiHCC5FqsRSaIsQhx44sohKcC5toUihqUjYxb8z8xw3jksLsmIn9sx43vOS
HFMMMccECZ749ogZNrGBL6sbSNn3gQwvKFg+DHmKLfZPcM+eZzIeqFGw76Tk3LPvneNj9JEb
Y8TxayoVHMmML+YLRyqWq8emmxP3ybcmuthDC222OyXS4fpEjjGgxh1rH0OTejP2PbF3whly
frewTw2puDbUcVp5kIM62437XHiPDeyy3FnkCXEuviG5D5YXjxrwvcAV6xluiR7za0qP7YUH
oa6X+E1zWzmOncdObsytcjuiSkpPqa3jZBFBgzFleDU/GcfloW1zhJqeJYxHLM8cK3VY1is5
xLJSGINW+5lo33dGDanMGYMyInYLB+hZLWddtqvUMpv9N8dNHJKnHdVZ4/hoMdtfmNhFPNdv
TmMdZSfGhNEUeAsy02eeRnYyuuZR7GPmp1U66lmODlmkKkwca91jj2zh1+XD6cQe6xjnIcbU
45gaI2Gb2c3xaSulvR/uWs9ZdX7210SjDCgPq336MxWjQqe53YXagQnPeWa3WXWWtCMLu+WE
GHE8tXiqc1tXXr4hHNKtkR7tgb8YB+U6Ca8V/R+rY7vdsTqm8B/Wsek7VpWvOi9ufXHf39bq
qd70KLvujteaPML9EbQnMvYldKF9MLQbODVGeDvXR76sTsr1uCz/RdLVf2Bgd391yyUlem44
7bq0RG7jgqfqnHfONr8qbN25f34AUEsBAhcLFAAAAAgAGlEiR2Tap+UxAgAAMgcAAAcACQAA
AAAAAAAAAACAAAAAAHN0ci5kYXRVVAUAB53K5lVQSwUGAAAAAAEAAQA+AAAAZwIAAAAA
</Image>

So the SQL selects all attributes owned by a element with stereotype «stereotype» with the name _imagethat have the tag <Image>  in their Default field.

1
2
3
4
5
6
7
8
9
'get all attributes with name _image that have shapescript in the default field and a parent with stereotype «stereotype»
dim sqlGetShapescriptAttributes
sqlGetShapescriptAttributes = "select a.ID from (t_attribute a " & _
                              " inner join t_object o on (o.Object_ID = a.Object_ID " & _
                              "                     and o.Stereotype = 'stereotype')) " & _
                              " where a.Name = '_image' " & _
                              " and a.[Default] like '<Image type=""EAShapeScript" & getWC & "'"
dim shapeScriptAttributes
set shapeScriptAttributes = getAttributesByQuery(sqlGetShapescriptAttributes)

Then we loop the schapescript attributes, decode the shapescript and save it as an individual text file.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
'loop the shape script attributes
for each shapeScriptAttribute in shapeScriptAttributes
    'get the stereotype
    dim stereotype as EA.Element
    set stereotype = Repository.GetElementByID(shapeScriptAttribute.ParentID)
    dim profile as EA.Package
    set profile = findProfilePackage(stereotype)
    'load the resultset in the xml document
    dim shapeScript
    shapeScript = decodeBase64zippedXML(shapeScriptAttribute.Default,"Image")
    if len(shapeScript) > 0 then
        dim scriptFile
        set scriptFile = New TextFile
        scriptfile.Contents = shapeScript
        'save the script
        scriptFile.FullPath = selectedFolder.FullPath & "\" & profile.Name & "\" & stereotype.Name & ".shapeScript"
        scriptFile.Save
        'debug info
        Session.Output "saving script: " & scriptFile.FullPath
    end if
next

The real difficulty in this script was to decode the shapescript, which is hidden in the method decodeBase64zippedXML  defined in the XML utility script. It first base64 decodes the contents of the tag, then saves it as a zip file, unzips the zip file, gets the text file in the zip file, and returns the contents of the text file. Then it deletes the temporary zip file and folder it was extracted to.

 Contributing

If you have shapescripts of your own that you wish to share you can send a github pull request, or an email to This email address is being protected from spambots. You need JavaScript enabled to view it..

Any bright ideas on how to document each of the shapescripts with an image of shape are welcome too.

This article was originally published at bellekens.com

Read 8169 times Last modified on Tuesday, 05 July 2016 02:23
Geert Bellekens

Geert Bellekens

Bellekens IT (Consultant)
 

Bellekens IT was founded in 2004 by Geert Bellekens and has a strong focus on UML, modelling and analysis methodology.

Geert Bellekens has helped several of the larger Belgian organizations to define and document their modelling method, train and coach the modelers and develop supporting tools.

Geert Bellekens is an acknowledged Enterprise Architect expert and has written numerous add-ins for Enterprise Architect, including the free open source EA Navigator and EA-Matic.

He is also one of the founding members and a regular speaker on the EA User Group events.

bellekens.com

2 comments

  • Comment Link philchudley Monday, 11 July 2016 09:28 posted by philchudley

    Great initiative!
    In addition to using the XML Utility Script you can simply copy the entire XML section including to the clipboard and paste into the Default section of the _Image attribute for your stereotyped element within your UML profile or MDG. Then open the shapescript using the profile helper and you should see the shapescript code.

    Phil

  • Comment Link Helmut Ortmann Thursday, 07 July 2016 09:55 posted by Helmut Ortmann

    Hi Geert,

    great idea. That's the stuff that really helps in everyday work.

    In the readme you may add links (e-book shape script, Thomas Kilian, ..)

    Thanks!

    Helmut

Login to post comments