Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: ron10023 on March 23, 2008, 07:53:24 pm
-
Hi everybody,
Is there a way to get the parent of a specific element?
When i try to use the ParentID attribute it always contains zero
-
Hi Ron,
Think about what you mean by "parent" and this will clear up quickly.
An element - at least an element in EA - always resides in (belongs to) a package. So there should always be a valid PackageID property. [Yes, I know there is an exception for Models (i.e. root packages) but that's not what you're talking about here.]
So for many situations the 'parent' of an element is the package that contains it. That's often how you will navigate the model hierarchy.
However, some elements are directly 'owned' by other elements. This can happen in the case of Class elements, which can contain other classes, embedded elements of various types, or some other situations. In these cases - and only in these cases - the ParentID of the 'child' element is populated with the ElementID of the 'parent.' In other cases the ParentID of the should be set to 0. When ParentID is set to 0 it indicates that this element is contained directly by the package, and not by another (intervening) element.
The above paradigm always works out in EA, because to be owned of an element, something must be owned by the same package as the element. I suspect - without proof, but I'd not care to test this on an important project - that if you built a project and got the PackageID of parent and child elements out of sync you would come to grief somewhere down the line.
HTH, David
-
The above paradigm always works out in EA, because to be owned of an element, something must be owned by the same package as the element. I suspect - without proof, but I'd not care to test this on an important project - that if you built a project and got the PackageID of parent and child elements out of sync you would come to grief somewhere down the line.
It won't show up as you expect in the project browser. However, it's a problem that can be fixed by the integrity checker.