Skip to content

Scripts in Enterprise Architect

Tobias Spears edited this page Mar 24, 2020 · 17 revisions

Home Basic UML Tools


Enterprise Architect offers the capability to edit, run, debug and manage scripts. Note: scripting is not available in the Professional and Desktop editions [Sparx].

Architecture

In short, EA serves as a ActiveX scripting host for 3 ActiveX scripting engines, each supporting a different language, more specifically

  • a VBScript engine (installed by default on Windows)
  • a JScript engine (installed by default on Windows)
  • a JavaScript engine (in the EA installation?)

VBScript is a subset of Visual Basic [Wikipedia]. JScript/JavaScript and Java are completely unrelated to each other [Wikipedia], but the syntax and naming conventions are similar. So depending on one's background, one may prefer one or the other language. For more information about VBScript and JScript, see VBScript and JScript Users' Guides and Language References.

Through scripts in EA, the internals of EA models can be accessed. E.g. the author of an class can be changed, a list of the elements in a package can be retrieved or tagged values can be added to elements fulfilling certain criteria. All the objects, methods, operators, etc. available in JScript, VBScript and JavaScript are of course also available in scripts in EA. This includes e.g. array handling, regular expressions and file processing.

Tips & tricks

Script names

Suggested naming conventions for scripts (prefixes):

  • CHG: scripts that change the model
  • DOC scripts that produce documentation of the model
  • INFO scripts that show information about the eap-file or related stuff
  • VAL scripts that validate models
  • scripts that start with an underscore should not/cannot be run directly

Reading and writing files

When using VBScript or JScript, files can be read and written through FileSystemObject. An object is created as follows:

' VBScript
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
// JScript
var fso;
fso = new ActiveXObject("Scripting.FileSystemObject");

See this introduction for more information about how to use FileSystemObject.

UTF-8 is not supported by FileSystemObject, so it may be a better option to use ADODB.Stream instead. ADODB.Stream is an ActiveX Data Object, and is as such part of any Windows installation in Windows Vista or later Windows version [Microsoft/Windows Data Access Components (MDAC/WDAC)].

// JScript
var fileName;
// fileName = ... full path
var stream = new ActiveXObject("ADODB.Stream");
stream.Type = 2 // text data (as apposed to binary data)
stream.Charset = "utf-8";
stream.LineSeparator = -1; // carriage return line feed
stream.Open();
// ...
stream.WriteText("text", 1);
// ...
stream.SaveToFile(fileName, 2);
stream.Close();

Including other scripts

!INC

Examples of useful scripts

Local Scripts

EA is shipped with examples, especially in JScript and VBScript, in the "Local Scripts" script group (Tools | Scripting > Scripts).

EAScriptLib MDG

EA also contains some helpful scripting functions that can be used in other scripts. In order to use these functions, the EAScriptLib MDG Technology must be enabled (Settings | MDG Technologies).

EAScriptLib MDG Technology

Scripts provided by ISO/TC 211 members

Example scripts on this page: https://github.com/ISO-TC211/UML-Best-Practices/tree/master/Scripts

Enterprise Architect VBScript Library

Library of wrappers and scripts for Enterprise Architect automation using VBScript: https://github.com/GeertBellekens/Enterprise-Architect-VBScript-Library. See also this tutorial: http://community.sparxsystems.com/tutorials/919-how-to-use-the-enterprise-architect-vbscript-library.

More information

Clone this wiki locally