Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: marke on February 10, 2012, 04:38:29 am
-
Hi,
The Package class Elements attribute help entry says it is "a collection of elements that belong to this package". Is that collection just the elements that are leafs of the package? Or does it include the whole tree beneath the package?
Experimentation suggests it is the former (just leaf elements) which I found a bit surprising.
If the former, is there an existing method to return the whole tree as a collection or do I need to implement a traversal method?
Thank you,
Mark
-
Personally I use a traversal method. Elements inside a package will have a packageID attribute that will be the parent package. That is the main thing I use to identify elements inside a certain package.
Let me know if you want more detail!
-
In general, Packages may have more Packages, Elements and Diagrams as children. Elements may have more Elements and Diagrams as children. Thus you need to do a traversal to pick up all the children below an element and construct the structure you wish to get out of it. This is pretty trivial using Javascript and recursion. ;)
Bjorn.
-
That has changed somewhen between 7.5 and 9.0 (don't remember exactly). In older EA builds you get everything - meaning direct elements AND embedded elements in those. Now you get only the elements without embedded ones. But you never get the recursive list of all contained packages. You need to traverse or to write some tricky SQL.
q.
-
Thank you for all the responses. In case anyone else stumbles across the same problem here is what worked for me:
function traverseAllElementsIn( elements ) // elements as EA.Collection
{
// Navigate the elements collection.
for ( var j = 0 ; j < elements.Count ; j++ )
{
var theElement as EA.Element;
theElement = elements.GetAt( j );
renameVerifMethod(theElement); // this does the work
var subElements as EA.Collection;
subElements = theElement.Elements;
if (subElements.Count > 0)
{
Session.Output("# of sub elements " + subElements.Count);
traverseAllElementsIn( subElements );
}
}
}
Mark
-
Have you tested that with sub-packages as well?
Because packages are a bit strange, they are both package and element...
Geert
-
Geert,
I tried it and this function does not traverse down through sub-packages - that's for another day (or an exercise for the reader ;)).
I found a model dump example jscript which would no doubt give tips on how to traverse sub-packages.
Mark
-
Allright, as long as you are aware of the issue..
Geert
-
I'll tell you what, the whole Packages are a package and element thing can make it a bit tedious. Especially because I use an interface to handle all "elements".
I think the reason for this though was to make relationships between EA.Elements, EA.Packages, and the diagram a bit more intuitive.
I supposed editing is also a bit easier.
-
You got it. It's called EAUI (EA Unique Interface).
q.