Author Topic: How to get package GUID in same leve by element GU  (Read 5361 times)

mohammed

  • EA User
  • **
  • Posts: 28
  • Karma: +0/-0
    • View Profile
How to get package GUID in same leve by element GU
« on: May 30, 2013, 08:52:17 am »
How to get package GUID in same leve by element GUId:
for example I have :
1) an element with guid 10001
2) in the same level I have a package with guid ??
how to get guid of that package by knowing the element guid ??

thanks ::)

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: How to get package GUID in same leve by elemen
« Reply #1 on: May 30, 2013, 09:56:56 am »
By checking element.packageid, getting the package and looking inside.

q.

Aaron B

  • EA Administrator
  • EA User
  • *****
  • Posts: 941
  • Karma: +18/-0
    • View Profile
Re: How to get package GUID in same leve by elemen
« Reply #2 on: May 30, 2013, 10:08:32 am »
Hi mohammed,

If you mean you have a reference to an EA.Element where Type = "Package" and you want to get the corresponding EA.Package object, simply pass the ElementGUID to GetPackageByGUID().  Both the EA.Element and corresponding EA.Package share the same GUID value.

Example:
EA.Package pkg = Repository.GetPackageByGuid(element.ElementGUID);

Aaron B

  • EA Administrator
  • EA User
  • *****
  • Posts: 941
  • Karma: +18/-0
    • View Profile
Re: How to get package GUID in same leve by elemen
« Reply #3 on: May 30, 2013, 10:17:08 am »
...Or if you are wanting to get a Package that is a sibling of your current Element, you will need to get the Parent package first, then loop it's Packages collection to find the package you want.

Example:
EA.Package parent = (EA.Package)repository.GetElementByID(element.PackageID);
for (short i = 0; i < parent.Packages.Count; i++)
{
  EA.Package pkg = (EA.Package)parent.Packages.GetAt(i);
}

I think this is effectively what qwerty was suggesting.