Search code examples
scriptingumlenterprise-architectactivity-diagram

Enterprise Architect scripting with java - activitydiagram entry point initial


I want to generate an activity-diagram with my java code. it work's to create an actionelement:

//Add the actionElement to the package
Element actionElement = elements.AddNew("MyFirstAction", "Action");
elements.Refresh();

//Add the element to the activity diagram
DiagramObject dob = dobs.AddNew("", "");       
dobs.Refresh();

//reference the DiagramObject to the before created element
dob.SetElementID(element.GetElementID());
dob.Update();
dobs.Refresh();

So I thought it will work's for the Initial (or EntryPoint) in the same way:

Element initElement = elements.AddNew("Start...","EntryPoint");

But the following Exception appears:

java.lang.Exception: Invalid parent for EntryPoint (Package)

Somebody can help me? My othe question is, if there is any Enumeration for the ElementTypes of the Collection? Because I only found the following information of the collection class..

AddNew (string Name, string Type)

But the information of the Type tells only "Type: String (up to 30 characters long)".

Here is a link to the Collection Class: http://www.sparxsystems.com/enterprise_architect_user_guide/9.2/automation/collection.html

Regards

EDIT

With help of Uffe I got the information of subtypes and types of some activity-diagram components. The "orginal name" is that name what you see in the GUI of the Enterprise Architect when you want to add a "New Element or Connector" :

  • original name: "Action"; type: "Action"; subtype: 0;
  • original name: "Activity"; type: "Activity"; subtype: 0;
  • original name: "Structured Activity" (Other->Simple Composite); type: "Activity"; subtype: 8;
  • original name: "Initial"; type: "StateNode"; subtype: 100;
  • original name: "Final"; type: "StateNode"; subtype: 101;
  • original name: "Flow Final"; type: "StateNode"; subtype: 102;
  • original name: "Decision"; type: "Decision"; subtype: 0;
  • original name: "Merge"; type: "MergeNode"; subtype: 0;
  • original name: "Decision"; type: "Decision"; subtype: 0;
  • original name: "Fork/Join" (horizontal); type: "Synchronization"; subtype: 0;
  • original name: "Fork/Join" (vertical); type: "Synchronization"; subtype: 1;
  • original name: "Diagram Legend"; type: "Text"; subtype: 76;
  • original name: "Synch"; type: "StateNode"; subtype: 6;

Uffe already explained it in his answer. Firstly create the Element with the type parameter and after that set the specific subtype. Don't forget the update() after this.

Element element = elements.AddNew("StartHere", "StateNode");
element.Subtype = 100;
element.Update();
elements.Refresh();

Thanks to Uffe again for this example:)


Solution

  • There is no element type enumeration, the element is simply specified as a string. The valid strings are listed in the help file, specifically in the Type attribute of the Element class (Automation and Scripting -- Enterprise Architect Object Model -- Reference -- Element Package -- Element Class).

    There isn't a unique element type string for each type of element EA supports. Instead, many elements have a subtype. This subtype is expressed as an integer (Element.Subtype), and most of them are not documented - but the initial activity of an Activity diagram happens to be one of the few that is.

    So in order to create an ActivityInitial element (as it is known in the GUI), you simply create the element specifying the type, and then set its subtype and update it.

    Element element = elements.AddNew("StartHere", "StateNode");
    element.Subtype = 100;
    element.Update();
    elements.Refresh();
    

    In order to find out the correct type/subtype combination for other elements, the simplest way is to create an element of the corresponding type in the GUI and then look it up in the database:

    select Object_Type, NType from t_object where Name = 'MyTestElement'