Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Neoris_alm on October 25, 2007, 01:29:14 pm
-
How can I make to insert a new element to EA from
another application? I try to use a java API, but I don´t see which classes have that operation ??
The elements that I need to Insert like new are Requirements and package and its relations.
EA has some another method to get this Integration like webservices ??
thanks
Israel Ruiz
-
Israel,
What you actually have to do in add a new element to the appropriate collection. You will call the collection's AddNew method to accomplish this.
This theme is repeated throughout the API, with minor variations in what you supply as values for the two parameters.
HTH, David
-
Ok :o , but Where can I find some examples about that.
or the Api documentation ??
thanks.
-
Israel,
You need to look in the SDK, which is now a section of the EA User Guide, or the EA Help file.
In contents, look up Extend Enterprise Architect - Software Developers Kit | Enterprise Architect Object Model.
The Reference section is what you want, though you might also want to read through the Using section too. There are some (very basic) code samples in the Reference section. These show several variations on the AddNew theme, and should be enough to get you started.
You can also search the forum for AddNew. You'll find a lot of general discussion, but also some code snippets.
David
-
Hi David!!
I looked for the examples but I don´t find anything about insert from Java api () a new Element. I do this
Repository r = new Repository();
r.OpenFile("c:\\ALM_Process.eap");
Collection <Datatype> coll = r.GetDatatypes();
coll.AddNew("New Requirement", "Requirement");
r.CloseFile();
it run without problems, but I don´t see any change on my
ALM_Process.eap
do u have some suggestion ??
-
Yes I do.
I should have mentioned this. However, it is one of the 'gotchas' in EA - it is almost impossible to figure out until you've seen it, and afterwards it is so obvious that you forget all about it.
After you create (or modify) anything in EA you need to call the thing's Update() method (there are no arguments). Until then EA really doesn't store the new thing or the changes. If you forget this method it is as if you never did the previous operation. In the case you mention you will get the symptoms you describe - nothing has happened.
Let me know if this gets you going.
David
-
Thanks David,
I follow your comments and I get it :)
also I found the steps into the "Help Contents" to Add new elemet in my Model
1. Call AddNew to add a new item
2. Modify the item as required
3. Call Update on the item to save it to the database
4. Call Refresh on the collection to include it in the current set
I´m grateful for your quickly answers
TA
Israel Ruiz
-
OK, good to know this is working for you.
The Refresh() call is not absolutely necessary, unless you will need to get the new item from its parent collection right away. If you are only going to create the item, and perhaps manipulate its properties, then you've got the appropriate object variable - the return value from AddNew().
However, if you are then going on to create another item, and might come back to the first (or any other scenario where you need to get an item from the parent collection) you will need to call Refresh(). This makes your copy of the collection accurately reflect the current contents.
Refresh() is also important when you have deleted items in the collection.
BTW, in some scenarios it is worth populating the collection with several items and the calling Refresh() once at the end of the sequence. This can save some time when you are adding many new items, but not fetching any until later.
David