Home - Helmut-Ortmann/EnterpriseArchitect_ScriptDotNet GitHub Wiki

EnterpriseArchitect_ScriptDotNet

Use the power of

for your EA Scripting and Querying.

Implement your EA Scripts in .NET, Java, or your preferred language like Pyton and make only the glue-code to EA in JScript, VB Script or JavaScript. The minimal EA glue-code is responsible for EA integration and passing the parameters to your target environment (.NET, Java, Python, etc.).

Benefits

  • Well known Software Life-Cycle
  • Let IDE and compiler work for you
  • A vast amount of libraries, examples and tutorials
  • Easy testing and debugging
  • With Project Search Scripts also non-SQL solutions are possible (Matrix, Recursive)
  • LINQ for SQL, the powerful way of SQL

Example Text to Speech

**In short: State of the art software development**

Principle

One line of code and you are in your Java, C#, VB, F#, C++ environment!

EA: VB Script glue-code

' Run the C#, VB, F#, C++ Console Programm,
result = RunCommand(myScript.exe, "DoTask1", guid, "", "") ' C# vb script glue-code
' Run the Java Class, let Java do everything
result = RunCommandJava("%EA_SCRIPT_HOME%", "SparxSystems.RepositoryInterface", " ", " "," ", " ") ' Java vb script glue-code
' Run Python with the file 'MyPythonFile.py'
result = runPython("%EA_SCRIPT_HOME%MyPythonFile.py", "MakeSomeThing", "", "", "")

.NET: See ScriptCSharp.cs

switch (command) {  // Decide what to do
    case: "DoTask1":
       var el = _repository.GetElementByGuid (guid); // get the passed element
       _repository.ShowInProjectView(el);            // show the passed element in project browser
    break;

    case: "DoTask2":
    break;
}

Java: See RepositoryInterface.java

public void PrintPackage( org.sparx.Package pkg)
    {
        Trace( pkg.GetName());
        Collection<org.sparx.Package> packages = pkg.GetPackages();
        for(short i = 0; i < packages.GetCount(); i++)
        {
            PrintPackage(packages.GetAt(i));
        }
    }

Python

    # get the first running EA object
    eaApp = win32com.client.Dispatch("EA.App")
    # get the Repository object
    rep = eaApp.Repository

    # get context element and its type
    type = rep.GetContextItemType()
    obj = None
    # Check if type is plausible
    if (type > 0):
        obj = rep.GetContextObject()
        name = obj.Name  

EA glue-code

Take the EA-Script Template and add three or so lines of code and you have done integration or the so-called glue-code. Decide whether you pass the environment like guid ot type to C# or let C# do it.

EA VB Scripts

You may condense this code section to (one line of EA VB Script code):

' Call C# "TraversePackage" and make everything there
runCommand "%EA_SCRIPT_HOME%ScriptCSharp.exe", "TraversePackage", "", ""

Examples

See Parts, EA VB Scripts

Try it

  1. Installation C#
  2. Tutorial C#
  3. Java
  4. Python
  5. Use it for other languages, VB, F#, C++, or?

Other languages

You can use every language which allows communicating with Windows COM like:

Pro

  • The language and infrastructure you are familiar with
  • Your established SW Life-Cycle

Cons

  • No context information for EA functions

Concept

  1. EA: Call Python
  2. Python:
    • Connect to EA (first EA instance)
    • Do your business
      • You have access to the full EA API

Example

The example is written in Python. The principle is the same.

# get the first running EA object
eaApp = win32com.client.Dispatch("EA.App")
# get the Repository object
rep = eaApp.Repository

# get context element and its type
type = rep.GetContextItemType()
obj = None
# Check if type is plausible
if (type > 0):
    obj = rep.GetContextObject()
    name = obj.Name  

Restrictions

If you load in your code a Repository you'll loose the connection to the EA GUI. This means you can't get selected items or output something to the EA GUI.

Participate & influence

I appreciate your opinions and advice!

You may want to participate:

  • Other Script languages like Java
  • New features
  • Your ideas

References