Displaying items by tag: scripts

The Enterprise Architect VBScript Library is an open source library of VBScripts written to be used in Enterprise Architect.

This article explains how to download, import and use the library in Enterprise Architect.

Initial Import

Initial scripts

The Enterprise Architect VBScript Library contains some scripts to load and save scripts from/to your file system, but before we can use those we have to import an initial set of scripts to get started.

After downloading the file select menu option Project|Data Management|Import Reference Data and choose the downloaded file. Make sure to select Automation scriptsand click Import.

This will import the minimum set of scripts required to load other scripts from the file system



VBScript library initial script set
VBScript library initial script set

Download library from GitHub

From the Enterprise Architect VBScript Library project page on GitHub you can either choose to download the library as a zip file, or download the repository in GitHub desktop.

VBScript library github

Load library into Enterprise Architect

Select scripts folderOne of the scripts in the initial set is the scriptLoadScripts in the group Script Management. If you execute this script you can choose the library folder from the library downloaded from GitHub.

The script will then scan the entire folder tree and it will load any .vbs file it can find.

For starters it might be interesting to only load the Frameworks scripts as they have the most chance of being useful to anyone.

If the LoadScripts script finds a script that already exists in Enterprise Architect it will ask to overwrite the existing scripts.

In order to know in which group the script belongs it will look for a the group indicator in the script.

'[group=Script Management]

This will tell the script that this script should go in the group Script Management. If the script indicator is absent it will assume the group name is the name of the folder where it was found.

After loading the scripts into EA make sure to press the refresh button to make the scripts appear in the GUI.

Refresh script tree

Saving all your scripts

In the script management group there also a script to save all your scripts to the file system.

In order to control where the script should go you can add the path indicator to the script like this

'[path=\Framework\Tools\Script Management]

The path indicator will control where to place the script relative to the chosen folder.

If the path indicator is absent the name of the script group will be used as name of the folder.

Being able to save and load the scripts from/to the file system now allows us to use version control on these scripts.

The library structure

The library is structured in two main parts.

  • Projects
    Contains an assortment of various scripts written for various projects.
  • Framework
    Contains the framework scripts that are meant to be used by other scripts
    • Utils
      Contains helper scripts and classes such as TextFile, SQL, XML etc..
    • Wrappers
      Contains the wrapper classes for EA elements such as TaggedValue, Script, ScriptGroup

The scripts in the projects folder can be used for inspiration, but it is mainly the scripts in the Framework part that are useful when writing scripts.

Using the library

The first thing you need to do when you want to use any of the framework classes is to include the framework in your script

!INC Wrappers.Include

This will include the “Include” script that takes care of including all the other scripts of the framework, including those of the Utils folder.

Then you can use the classes defined in the library. For eaxample, if you want to have the user select a directory you can use following code

'get the folder from the user
dim folder
set folder = new FileSystemFolder
set folder = folder.getUserSelectedFolder("")

The classes in the library contain both properties as operations. You can use the properties as you would expect from “real” classes.

'show messagebox with the name of each subfolder
dim subfolders, subfolder
for each subfolder in folder.SubFolders
    msgbox "subfolder name: " & subfolder.Name


Have you written any VBScripts for Enterprise Architect you would like to share? If you would like to contribute to the Enterprise Architect VBScript library you can email me at This email address is being protected from spambots. You need JavaScript enabled to view it.

Published in Tutorials
Tagged under


Hippo Software's recently extended workshops are designed to expand and enhance delegates' knowledge of Enterprise Architect:


           EA Document Workshop – create custom document templates


           EA Excel Data Transfer Workshop – easily share requirements or other data


           EA Scripting Workshop – facilitate repetitive or complex tasks on models


           EA Profiles Workshop – define custom diagrams, toolboxes, elements and relationships


For more information, please visit the Hippo Software website below:




Published in News

I recently imported a number of requirements in my Enterprise Architect project with the following details: title, reference (stored in the requirement's alias), and description. By default Sparx Enterprise Architect sorts requirements within a given package by the element's name in the alphabetical order. When a package contains various types of elements (e.g. classes, interfaces, use cases, etc.), each group of elements from the same type is sorted separately. The following illustrates a mix of requirements, classes, and interfaces created within a package, in their default sorting order:

sparx enterprise architect project browser


Going back to my requirements, I needed to sort them by the alias value e.g. REQ-TEST-001, REQ-TEST-002, REQ-TEST-003, etc. On the following screenshot, I illustrated on the left hand side the default sorting order in Enterprise Architect project browser, and on the right hand side the list of requirements in the desired alias order. 

sparx enterprise architect project browser sort by script


This article explains how to create and use an Enterprise Architect Project Browser script aimed at sorting elements from a selected package by the alias name. An additional script is provided at the end of the article to sort elements by a dedicated Tagged Value called "SortingOrder".

Enterprise Architect Project Browser scripts

Enterprise Architect lets you create project browser scripts. Once created in your project, these are available via a right click on a selected package from the browser, as illustrated below:

sparx systems enterprise architect project browser script


Sort by alias project browser script

To add the SortByAlias Project Browser script to your modelling project:

Step 1: open the scripting view using the Enterprise Architect menu Tools > Scripting.

Step 2: click on "New Project Browser Group" to store all user-defined scripts, e.g. Project Browser scripts.

Step 3: click on "New script > New VBScript" to define the "Sort By Alias" script, e.g. SortByAlias.

sparx enterprise architect project browser script sortbyalias

Step 4: open the script and copy/paste the following content (or download the VBScript text file here). 

  1. option explicit
  2. !INC Local Scripts.EAConstants-VBScript
  3. !INC EAScriptLib.VBScript-Logging
  4. ' Script Name: SortbyAlias 
  5. ' Author: Guillaume FINANCE, guillaume[at]umlchannel.com
  6. ' Purpose: Sort elements contained in the selected package from the Project Browser by the Alias name
  7. ' Date: 03/04/2014
  8. sub SortDictionary (objDict)
  9.    ' constants
  10.    Const dictKey  = 1
  11.    Const dictItem = 2
  12.    ' variables
  13.    Dim strDict()
  14.    Dim objKey
  15.    Dim strKey,strItem
  16.    Dim X,Y,Z
  17.    ' get the dictionary count
  18.    Z = objDict.Count 
  19.    ' sorting needs more than one item
  20.    If Z > 1 Then
  21.      ' create an array to store dictionary information
  22.      ReDim strDict(Z,2)
  23.      X = 0
  24.      ' populate the string array
  25.      For Each objKey In objDict
  26.          strDict(X,dictKey)  = CStr(objKey)
  27.          strDict(X,dictItem) = CStr(objDict(objKey))
  28.          X = X + 1
  29.      Next 
  30.      ' perform a a shell sort of the string array
  31.      For X = 0 To (Z - 2)
  32.        For Y = X To (Z - 1)
  33.          If StrComp(strDict(X,1),strDict(Y,1),vbTextCompare) > 0 Then
  34.              strKey  = strDict(X,dictKey)
  35.              strItem = strDict(X,dictItem)
  36.              strDict(X,dictKey)  = strDict(Y,dictKey)
  37.              strDict(X,dictItem) = strDict(Y,dictItem)
  38.              strDict(Y,dictKey)  = strKey
  39.              strDict(Y,dictItem) = strItem
  40.          End If
  41.        Next
  42.      Next
  43.      ' erase the contents of the dictionary object
  44.      objDict.RemoveAll
  45.      ' repopulate the dictionary with the sorted information
  46.      For X = 0 To (Z - 1)
  47.        objDict.Add strDict(X,dictKey), strDict(X,dictItem)
  48.      Next
  49. ' sort the package elements based on the new sorting order
  50. dim newOrder
  51. newOrder = 0
  52. dim theItem
  53. dim eaelement
  54.  for each objKey in objDict
  55. theItem = objDict.Item(objKey)
  56. Set eaelement = Repository.GetElementByGuid(theItem)
  57. 'change the position of the element in the package to the new sorting order value
  58. eaelement.TreePos = CLng(newOrder)
  59. eaelement.Update()
  60. newOrder = newOrder + 1
  61. next
  62.    end if
  63. end sub
  65. sub sortElementsbyAlias (selectedPackage)
  66. LOGInfo("Processing selected package " & selectedPackage.Name)
  67. dim elements as EA.Collection
  68. dim i
  69. dim processedElements
  70. set processedElements = CreateObject( "Scripting.Dictionary" )
  71. set elements = selectedPackage.Elements
  72. for i = 0 to elements.Count - 1
  73. dim currentElement as EA.Element
  74. set currentElement = elements.GetAt( i )
  75. LOGInfo("Processing " & currentElement.Type & " no " & i & " with alias " & currentElement.Alias & "(" &  currentElement.ElementGUID & ")")
  76. processedElements.Add currentElement.Alias, currentElement.ElementGUID
  77. next
  78. LOGInfo("Sorting package elements")
  79. SortDictionary processedElements
  80. end sub
  81. '
  82. ' Project Browser Script main function
  83. '
  84. sub OnProjectBrowserScript()
  85. Repository.ClearOutput "Script"
  86. LOGInfo( "Starting SortbyAlias script" )
  87. LOGInfo( "==============================" )
  88. ' Get the type of element selected in the Project Browser
  89. dim treeSelectedType
  90. treeSelectedType = Repository.GetTreeSelectedItemType()
  91. select case treeSelectedType
  92. case otPackage
  93. ' Code for when a package is selected
  94. dim thePackage as EA.Package
  95. set thePackage = Repository.GetTreeSelectedObject()
  96. sortElementsbyAlias thePackage
  97. Repository.RefreshModelView (thePackage.PackageID)
  98. case else
  99. ' Error message
  100. Session.Prompt "This script does not support items of this type.", promptOK
  101. end select
  102. end sub
  103. OnProjectBrowserScript

Step 5: save the script (Ctrl-S).

Step 6: right click on the target package from the Project Browser where elements need to be sorted by the alias, and select Scripts > SortbyAlias

Result: the requirements have been sorted by the alias value as illustrated below.

sparx-enterprise-architect-project_browser_script_sortbyalias_running result

This sorting order is consistent with the requirements' alias values:

sparx enterprise architect project_browser_script_sortbyalias done

Sort by tagged value 'Sorting Order' project browser script

In some cases, the alias value may not be appropriate to sort your elements within the selected package. Based on the above SortByAlias script, I created the SortbyTaggedValue_SortingOrder script aimed at sorting elements using a tagged valued created for this purpose, SortingOrder.

To illustrate its use, I added the SortingOrder tagged value to each requirement:

sparx enterprise architect project_browser_script_sortby tagged value

To add the SortByTaggedValue Project Browser script to your project:

Step 1: open the scripting view using the Enterprise Architect menu Tools > Scripting.

Step 2: open the Project Browser scripts group.

Step 3: click on "New script > New VBScript" to define the "Sort By Tagged Value" script, e.g. SortbyTaggedValue_SortingOrder.

Step 4: open the script and copy/paste the following content from the script that can be downloaded here

Step 5: save the script (Ctrl-S).

Step 6: right click on the target package from the Project Browser where elements need to be sorted by the alias, and select Scripts > SortbyTaggedValue_SortingOrder.

sparx enterprise architect project_browser_script_sortby tagged value open


Result: the requirements have been sorted by the SortingOrder tagged value as illustrated below.

sparx enterprise architect project_browser_script_sortby tagged value result


This article illustrated how Sparx Enterprise Architect can be tailored to introduce new features via user defined scripts, e.g. to apply a new sorting rule on the elements from a selected package. It could be further improved e.g. to sort elements within the sub packages and so on.


Published in Community Resources
Tagged under
Monday, 10 March 2014 11:59

eaDocX v3.4 beta available

Additional document creation options from your Enterprise Architect model are now available with the release of the eaDocX v3.4 beta.

 This latest eaDocX release allows you to:

- construct documents and document sections based on your model views

- use instance classifiers just like any other relationship to provide new document structures

- work with EA scripts to deliver even more tailored document formatting options

- plus other customer requested enhancements

eaDocX v3.4 is compatible with EA v11.

Read more and download a free trial at www.eadocx.com

Published in News

A colleague recently enquired about a simple way to run a batch import of several XMI files into an Enterprise Architect project. The client's project required importing a rather large number of XMI files, created from various Enterprise Architect projects via the standard XMI export (note : each file store an extraction in the XMI format from a selected part of the modelling project). Having to import each XMI file is too cumbersome, and Enterprise Architect's existing "Batch XMI Import" is limited to controlled packages i.e. involving a VC repository like SVN set up with the current project.

This article explains how to create in your Enterprise Architect project a VBScript that can be used import a batch of XMI files, located on a local or networked drive, within a selected package from the browser.

Step 1: open the scripting view using the menu Tools > Scripting.

Step 2: click on "new normal group" to store all user-defined scripts, e.g. MyScripts.

Step 3: click on "new script > new VBScript" to define the Batch XMI Import script, e.g. BatchXMIImport.

enterprise architect scripting view

Step 4: open the script and copy/paste the following content (or download the VBScript text file here). 

  1. option explicit
  2. !INC Local Scripts.EAConstants-VBScript
  3. '
  4. ' Script Name: XMIImportFiles
  5. ' Author: G.Finance guillaume[at]umlchannel.com 
  6. ' Purpose: Batch import of XMI files to the selected package
  7. ' Date: 13/01/2014
  8. ' HOW TO USE  : 1. Set the target directory in the targetFolderA variable (use \\ for each backslash) ; you may enable additional folders if required
  9. '               2. Add each XMI filename to process into the "fileList" array variable
  10. '             3. Run the script
  11. '
  12. '
  13. ' [USER ACTION 1] : update the target folder where the files to process are located
  14. dim targetFolderA
  15. targetFolderA = "C:\\temp\\"
  16. ' Additional target folders to use if required
  17. 'dim targetFolderB
  18. 'targetFolderB = "D:\\"
  19. 'dim targetFolderC 
  20. 'targetFolderC = "E:\\"
  21. '
  22. '
  23. ' ArrayList Object to store the name of each file to process (including the folder name, using one of the "targetFolder" variables)
  24. dim fileList
  25. Set fileList = CreateObject("System.Collections.ArrayList")
  26. ''[USER ACTION 2] : update the following list with the name of each file to process, specifying first the associated targetFolder variable
  27. fileList.Add targetFolderA + "class.xml"
  28. fileList.Add targetFolderA + "deploy.xml"
  29. fileList.Add targetFolderA + "uc.xml"
  31. ''add new lines above if required
  32. dim projectInterface as EA.Project
  33. dim result
  34. set projectInterface = Repository.GetProjectInterface()
  35. sub XMIImportFiles()
  36. Repository.EnsureOutputVisible "Script"
  37. Repository.ClearOutput "Script"
  38. Session.Output( "VBScript XMI Import Files" )
  39. Session.Output( "=======================================" )
  40. ' Get the selected package to import the XMI files 
  41. dim contextObjectType
  42. contextObjectType = Repository.GetContextItemType()
  43. ' Check if the selected element is a package ; if not display a message and exit
  44. if contextObjectType = otPackage then
  45. ' Get the context object as a package
  46. dim contextPackage as EA.Package
  47. set contextPackage = GetContextObject()
  48. Session.Output( "Selected Package : " & contextPackage.Name )
  49. Session.Output("TARGET PACKAGE GUID = " & contextPackage.PackageGUID & "(ID : " & contextPackage.PackageID & ")" )
  50. ' Process each XMI file set in the fileList Array Object
  51. Dim xmiFile
  52.         For Each xmiFile In fileList
  53.             Session.Output("Processing " & xmiFile & "..." )
  54. ''Import the content of the XMI file to the selected package
  55. result = projectInterface.ImportPackageXMI(projectInterface.GUIDtoXML(contextPackage.PackageGUID), xmiFile, 1, 1)
  56. Session.Output(result)
  57. Next      
  58.    }
  59. else
  60. ' Package is not currently the context item
  61. MsgBox( "This script requires a package to be selected." & vbCrLf & _
  62. "Please select a package and try again." )
  63. end if
  64. end sub
  65. XMIImportFiles

Step 5: set the folder name(s) and filenames to process by updating the script's content.

  • Let's say you need to import C:\old\usecases.xml and C:\current\class.xml XMI files, created from a separate EA project.
  • Update targetFolderA variable on line 15, using \\ for each backslash: targetFolderA = "C:\\current\\"
  • Uncomment targetFolderB variable on line 17: dim targetFolderB
  • Update targetFolderB variable on line 18: targetFolderB = "C:\\old\\" 
  • Set the values in the ArrayList object (from line 27): fileList.Add targetFolderA + "class.xml", fileList.Add targetFolderB + "usecases.xml"
  • Save (ctrl-S)

Step 6: select the target package (or view) from the Project Browser, and click on the "run script" to import all XMI Files (important : it is not possible to select a Model Root as the target)

scripting_enterprise-architect-batch-xmi-file-import run script

 Note: results and notification messages are displayed in the System Output view (opened automatically once the script starts running)

scripting_enterprise-architect-batch-xmi-file-import run script

 Result: the content of both XMI files is available from the selected package within the Project Browser.

scripting_enterprise-architect-batch-xmi-file-import result

Note : if your XMI file contains a model root, or a view (package at N+1 level) such as "test" from the above Project Browser illustration, it will be imported as a package within the selected package or view.

Published in Community Resources
Tagged under


Hippo Software introduces a new 2-day ‘EA Scripting Workshop’ that teaches delegates how to write scripts to control and update models in Enterprise Architect. Delegates use VBScript to automate repetitive tasks such as updating tagged values, to manipulate diagrams, to perform a complex search and to transfer data to/from MS Excel.


Visit the Hippo Software website for details of our full range of training courses and workshops.

Hippo Software provides competitive prices for on-site or webinar training, for small or larger groups of delegates.

Published in News