No 58A, New No 73,
Thirumangalam Road,
Chennai-600 049


Category: EA Automation

EA AutomationSparx Systems Enterprise Architect

How to create model based JavaScript Add-ins using Enterprise Architect 15

One of the latest features of Sparx Enterprise Architect 15 is the model based add-ins which can be created using JavaScript.  These model based add-ins are defined by a combination of Receptions, Attributes and Operations which can be easy added in a model by just creating with a valid stereotyped classes.

Assuming you have a basic knowledge in Sparx Traditional add-ins, broadcast events and JavaScript.

Why model based add-ins

  • Accessed by all the users with in a model
  • Purely Model specific
  • No installation, registry entries , distribution or license worries
  • Self-Documenting as everything is modelled and created directly in EA


  • Signal Reference Library ( Broadcast Events ) –  Defines the entry points to the add-In similar to the com class in the traditional add-ins
  • Referencing relevant signals in the receptions

What is Signal Reference Library

These are Signal elements which contain definitions of all the Enterprise architect broadcast events. Signals that are added to the add-in will receive an event when triggered. EAExample model contains all the broadcast event signals under the package Example Model.EA 15 Examples.Dynamic Model Based Add-Ins.Broadcast Types

Mandatory Signals or Events for Add-in

  • EA_Connect
  • EA_GetMenuItems
  • EA_MenuClick

All the available event references examples can be found here:


To Create an JavaScript Add-In

  1. Create a Signal Reference Library referring EAExample model. (Simple way would be just do an XMI export of the Broadcast Types package from EA model and import into your working model).
  2. Create a package in the root node for modelling the add-in

  1. Create a class object with stereotype JavascriptAddin ( this stereotyped element can be found in Model Add-Ins tool box as shown below

  1. The name of the above defined will be used in the JavaScript code. In our case it will be “Javascript Addin”
  2. Add the signal reference in the created class using the reception.
    • To Access Reception Right-click on the Class element and select the ‘Features | Receptions’ option. The Features window displays, at the ‘Receptions’ page.
    • Add the required events by clicking the button to the right of the New Receptiontext in the ‘Name’ column , the dialog will show the available Signals ( it will automatically fetch the parameters details from the object )

  • Once selected all the added signals will be displayed in the class object.

  1. After adding these events, it time to play with some JavaScript codes.
  2. Please open the behavior window (Develop > Source Code > Behavior) make sure the created class object “Javascript Addin” has been selected. It will show all the added events to which we need to add the code

  1. Codes for these events are similar to the traditional add-ins ( please refer the attached model for more details )
  1. Finally make sure the add-in is enabled. To enable the add-in Specialize -> Manage-Addin and please click Load on startup

  1. Once the add-in is loaded you can find it in the ribbon


For more details or customization please contact info@sparxsystems.in

EA AutomationSparx Systems Enterprise Architect

Execute Enterprise Architect Scripts from an External Program

We can execute Enterprise Architect Scripts from an external C# Application. Enterprise Architect supports a flexible and easy to use scripting capability. Enterprise Architect supports three scripting languages JavaScript and Microsoft JScript/VBScript.


  • Hassle-free updates in restricted environments – Not necessary to re-install addins
  • Introduce new feature in less time – Create New functionality using Scripts
  • Deploy changes to all model users -Scripts are stored in repository
  • Scripting is an interesting feature in Sparx Enterprise Architect. This aid us to do many things using Scripts and play with the active models


  • Certain limitations within scripts discussed in the article below.


  • The reader has a fairly good understanding of creating an Enterprise Architect Addin or writing an application that can use Enterprise Architect. Refer to below references if you need more information on these
    • To create an Addin from scratch refer this link 
    • Download Skeleton for creating an Add-In using the C# Language from this link

How to invoke Scripts from an External Application

  • Create an application and get a handle of Enterprise Architect

select script.ScriptID as SCRIPTID, script.Notes as NOTES, script.ScriptName as SCRIPTNAME, script.Script as SCRIPTGroup from t_script script where script.ScriptAuthor IS NOT NULL

  • Execute above Query to get the set of Script information
  • Parse the XML Output to get the Script Content based on Script Name and Guid by user selection
  • Save this script content in a string and pass as an argument for IncludeScripts method
  • Use ScriptControlClass to invoke the Enterprise Architect script.
    Refer below code
ScriptControlClass scriptController = new ScriptControlClass();
scriptController.Language = this.language.name;
scriptController.Timeout = -1;
scriptController.AddObject(“Repository”, Session.Repository);
//Add the actual code. This must be done in a try/catch because a syntax error in the script will result in an exception from AddCode
//first add the included code
string includedCode = IncludeScripts(scriptcontent); //pass script content string
//then add the included code to the scriptcontroller
catch (Exception e)
  • Add Reference for ScriptControlClass to invoke Enterprise Architect selected scripts.
  • Set AddObject to Active Enterprise Architect repository.
  • Replace all the !INC with actual codes in scriptcontent


Script should not include any Enterprise Architect specific keywords.

  • It should not use “as”
    • Correct Syntax : Var ele;
    • Incorrect Syntax : Var ele as EA.Element;
  • Script should not use any static functions like
    • “Session”.Eg.Session.Output,Session.Input,Session.Prompt
  • Repository and !INC are the only Enterprise Architect specific keywords supported

Certainly, users could develop an external program to handle scripts inside EA. Please drop your comments below if you have any queries.

Drop mail to info@sparxsystems.in for any assistance.

Document GenerationEA AutomationSparx Systems Enterprise Architect

Generating Documents using Document Scripts in Enterprise Architect

Sparx Systems Enterprise Architect is one of the very few tools that have the capability to generate documents on go from a centralized repository. Enterprise Architect has features to customize document contents using user templates, fragments, style sheets, cover pages and headers, and footers.

  • Document Script in fragments is a new option that is introduced in Enterprise Architect 13.
  • Used generally for generating complex documents from Enterprise Architect.

Custom Script vs Document Script

  • Custom script (Introduced in EA 11): Script returns a value that can be used in the fragment using the ‘custom’ field.
  • Document script (Introduced in EA 13): A combination of scripts and templates. The script calls another Template and passes the ID of an object to be reported

How does Document Script work?


Advantages of Document Script:

  • Flexibility in reporting desired fields in the desired order
  • Loop through or mix and match details in a custom way, as per the requirements.
  • Removes the need to write an external add-in to generate custom documents from the model.

Steps to create Document using Document Scripts:


  • From the Above business process diagram, we are going to generate all the diagram objects from the parent package.
  • Initially have created a Template like the below with package and element section enabled.


  • Under the Diagram Objects heading have inserted a new fragment and inside the fragment have enabled the Custom Section as below


  • To create a document script Fragment -> Document Options ->Custom Query -> Document Script and in the dropdown select the script which is written for document generation.


  • Reference the ID of the element or Package currently being processed by the document template, using the #OBJECTID# or #PACKAGEID#
  • Process Package script does the magic of rendering the objects in an order to a document.
  • Script which needs to be used in the Document script should always return an RTF

      var docGenerator as EA.DocumentGenerator;

        docGenerator = Repository.CreateDocumentGenerator();

        if ( docGenerator.NewDocument(“”) )


            docGenerator.DocumentElement(ElementID,Heading Depth,”templateName”); // Used to add the element details in rtf

             var rtf = docGenerator.GetDocumentAsRTF();

            return rtf;


  • For more details on attributes and methods of DocumentGenerator class please refer to Sparx Help on Document Generator class
  • In the document script, a template should be referred to so that the data will be formatted and printed based on that template.
  • For e.g. From the below package structure in Enterprise Architect


  • If the documentation is generated at the package level (BP00100) and the script for rendering all the diagram objects of a diagram
  • We need to pass the packageID as the parameter in the document script.
  • In the script, the main function rtf should be returned

function main(packageID)


var docGenerator as EA.DocumentGenerator;

docGenerator = Repository.CreateDocumentGenerator();

if ( docGenerator.NewDocument(“”) )




var package as EA.Package;

package = Repository.GetPackageByID(packageID);

var diagram as EA.Diagram;

diagram = package.Diagrams.GetAt(0);

var diagramObjects as EA.Collection;

diagramObjects = diagram.DiagramObjects;

for ( var i = 0 ; i < diagramObjects.Count ; i++ ) {

var diagramObject as EA.DiagramObject;

diagramObject = diagramObjects.GetAt( i );

var currentElement as EA.Element;

currentElement = Repository.GetElementByID(diagramObject.ElementID);

if(currentElement.Type != “Note” && currentElement.Type != “ActivityPartition” && currentElement.Type != “Pool” && currentElement.Type != “Lane”)








var rtf = docGenerator.GetDocumentAsRTF();

return rtf;


return “”;


  • Templates inside the script can be mentioned as below

var ACTIVITY_TEMPLATE = “Activity_Report”;


  • The above described is an example of generating a document using a document script. You can download this entire sample model with document generation scripts and templates from https://sparxsystems.in/Downloads/DocumentScriptTest.eap
  • Any complex logic can be used in the script but finally, it should return an RTF. 

Further Information
Please contact us or write an email to info@sparxsystems.in to have a live demo of the new EA 16 features and capabilities.