Book a Demo

Author Topic: Retrieving the Package above an element  (Read 6865 times)

tzafrir

  • EA User
  • **
  • Posts: 127
  • Karma: +0/-0
    • View Profile
Retrieving the Package above an element
« 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...?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Retrieving the Package above an element
« Reply #1 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