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.
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.
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.
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.
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:
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.
Then we loop the schapescript attributes, decode the shapescript and save it as an individual text file.
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.
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