Sparx Systems Forum

Enterprise Architect => General Board => Topic started by: tzafrir on January 07, 2016, 12:33:21 am

Title: Retrieving the Package above an element
Post by: tzafrir on January 07, 2016, 12:33:21 am
Hi,
I am trying to retrieve the id of a Package and load the package that is located above a specific element.
PackageId and ParentId either give an Id that does not exist or does not return anything even though a package exist above the element

i.e. something like this:
EA.Element elem = <retrievedElement>;
int packageId = elem.PackageID;
EA.Package parentElement3 = (EA.Package)repository.GetElementByID(packageId);
or
int parentId = elem.ParentID;
EA.Element parent2Element = repository.GetElementByID(parentId);
                       
Is there a more convenient way to do it, because this does not seems to be the one...?
Title: Re: Retrieving the Package above an element
Post by: Geert Bellekens on January 07, 2016, 01:41:12 am
Element.PackageID gives you a PackageID (duh) and you can't use the PackageID get get an Element.
Use Repository.GetPackageByID(myElement.PackageID) to get the owning package.
The PackageID is always filled in.

ParentID is the ElementID of the owning element. Since elements aren't always owned by a parent Element this often returns 0
You can use the ParentID in Repsitory.GetElementByID() but if you are only after the Package then you don't need to.

Geert