EA AutomationSparx Systems Enterprise Architect
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.
Pros
- 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
Cons
- Certain limitations within scripts discussed in the article below.
Assumptions
- 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
How to invoke Scripts from an External Application
- Create an application and get a handle of Enterprise Architect
|
- 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 try { //first add the included code string includedCode = IncludeScripts(scriptcontent); //pass script content string //then add the included code to the scriptcontroller scriptController.AddCode(includedCode); } catch (Exception e) { MessageBox.Show(e.Message); } |
- 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
Limitations
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.