1
votes

I have few short questions regarding Enterprise architect.

My question is regarding the automation interface. When following the instructions provided on this page: http://www.sparxsystems.com/uml_tool_guide/sdk_for_enterprise_architect/colle... in order to add a new element to the collection ( and the .eap file) it does not add the element. I can get data from the elements, modify and even delete them, but adding a new element does not work?

Instructions provided:

Call AddNew to add a new item. Modify the item as required. Call Update on the item to save it to the database. Call Refresh on the collection to include it in the current set.

my java example:

elements is a collection of all the elements in the model...

 org.sparx.Element elementEa = elements.AddNew("Requirement", "non-functional");
 elementEa.Update();          
 elements.Refresh();

With the api is it possible to change the id or guid of an element since there are no methods specified in org.sparx for that?

One last thing... Is it possible to create a custom element in EA, for example a requirement which will not have the standard properties like difficulty, priority etc.. , but will have others? (normal properties, not tagged values)

2

2 Answers

3
votes

The arguments to AddNew() are Name and Type, so to create a Requirement element you should specify "SomeRequirementName" and "Requirement".

You can't change the ID or GUID through the API, and your models would crash and burn if you did (connectors would be left dangling, elements would vanish from diagrams, etc, etc).

With an MDG Technology you can create very detailed stereotyped elements if you like, with their own visual representations (shape scripts) etc, but if you're after creating an element type with its own properties dialog the answer is no; there is no hook for a custom dialog in the API.

1
votes
Collection<Package> packageCollection = myPackage.GetPackages();
Package consolidatedCfsSpecPackage = packageCollection.AddNew("somePackageName", "");
if (!consolidatedCfsSpecPackage.Update()) {
    System.err.println("Not Updated: somePackageName");
}
packageCollection.Refresh();

This works for me. I suggest you to check return value of elementEa.Update() method you called. If it returns false, you can get the reason by calling elementEa.GetLastError().