How to use the Enterprise Architect VBScript Library

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 scripts and click Import.

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

 

 

[ecwid_product store_id=”6824265″ product_id=”58361080″]

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 script LoadScripts 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 int he 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 example, 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
next

Contributing

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 geert@bellekens.com

Published by

Geert Bellekens

Freelance UML and Enterprise Architect consultant

5 thoughts on “How to use the Enterprise Architect VBScript Library”

  1. Hi Geert,

    your sripting library is great! It’s a fast way to quickly get results without IDE and..

    In my opinion it’s better to initialize arrays to easy handle empty result sets. See eg XML.vbs: Dim result result = Array() ‘ Initialize to prevent out of range UBOUND (get -1 for empty)

    Personally I prefer ‘CreateObject(“System.Collections.ArrayList”)’ but I don’t know all the pros and cons.

    Find as attachment the two scripts: – Bookmark.vbs (handle bookmarks, eg. Search Window with standard searches) – Clipboard.vbs (handle Clipboard, eg: Search Window with SQL and GUID for elements/packages)

    Both with testcases, not yet complete or fully tested

    Kind regards,

    Helmut

  2. Hi Helmut,

    Thanks, I whish I discovered sooner that VBScript does classes as well 😉

    You are probably right with regards to the array initialization. I try to avoid those as much as possible (and use ArrayList wherever possible, but a two dimensional array was easier to use in this case then an ArrayList of ArrayLists). I’ll have a look at it one of these days.
    I’m looking forward to your scripts (which you’ll have to email since these wordpress comments don’t do attachments)
    I can add them for you to the library, or if you prefer you can add them yourself on Github. That way you get the credits for your code, whichever you prefer.

    Geert

  3. Hi Geert,

    Awesome library, especially the load/save scripts feature.

    I forked it on GH and added the automation.xml file in the root as it is pretty inconvenient to have to chase for the file, wait for it via email and then reload.

    Maybe would it be good to have a simple one for bootstrapping the whole thing and just having the load scripts in it to prime the system.

    As well as a preference somewhere so that we do not have to respecify the scripts folder every time on save (this itch will be annoying me I guess, so, I may do just something about it).

    There are some extra files in my fork but I do most of my work on a private Bitbucket repo, your being set as upstream.

    On interesting part is that I made classes out of your ExcelImporter v4 VBA code so that this can be run directly from inside EA.

    FWIW, I am working on the other side of the “Project A” (FYI there are remnants of the full A name in the scripts).

    If you are in for a drink or chat, maybe we can find a slot to do so.

    1. Hi Philippe,

      Thanks. I’m not sure I understand what you mean by bootstrapping etc.. but you better explain that to me in person one day.
      I know there are still references to Project A, I just didn’t want it to be too much “in your face”.
      On Mondays, Wednesdays and Friday’s I’m usually at work in Brussels. Maybe we dan do lunch together sometimes? Email me with some available slots.

      Regards

      Geert

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s