Book a Demo

Author Topic: Retrieving the package of a package elemen  (Read 6101 times)

beginner

  • Guest
Retrieving the package of a package elemen
« on: June 10, 2010, 08:35:40 pm »
Assume I had retrieved the element of a package. How can I retrieve the package of this element (the one where I picked it)?

Here's a sample code:
my $p = $rep->GetTreeSelectedObject();
my $pe = $p->Element;
my $pep = $rep->GetPackageById ($pe->PackageID);
$rep->log ("package of " . $p->Name . " is " . $pep->Name);

When I run that script EA returns the parent element of the according package and NOT the package itself.

Either I'm doing something completely wrong (it's quite hot here) or this is bug or someone has a good explanation. Who can help?

b.

Frank Horn

  • EA User
  • **
  • Posts: 535
  • Karma: +1/-0
    • View Profile
Re: Retrieving the package of a package elemen
« Reply #1 on: June 11, 2010, 12:39:15 am »
$pe->PackageID returns the ID of the package containing $pe, so you get the parent package allright.

Maybe you want

my $pep = $rep->GetPackageById ($pe->ElementID);

(provided $pe->ElementID == $p->PackageID)

beginner

  • Guest
Re: Retrieving the package of a package elemen
« Reply #2 on: June 11, 2010, 12:55:12 am »
Not so. A package contains an element ($p->Element) and I would assume that $p->Element->PackageID == $p->PackageID. But it seems to be $p->ParentID.

And: GetPackageById needs a PackageID, not an ElementID. So
Quote
my $pep = $rep->GetPackageById ($pe->ElementID);
would not work.

b.

Frank Horn

  • EA User
  • **
  • Posts: 535
  • Karma: +1/-0
    • View Profile
Re: Retrieving the package of a package elemen
« Reply #3 on: June 11, 2010, 01:15:21 am »
OK, so a package has 2 IDs, an ElementID and a PackageID, both of the same type, but not equal?

In that case, I wouldn't know how to get the package object  if you have an element which you know represents a package. Except for looping through all the packages within the parent package's packages collection...

beginner

  • Guest
Re: Retrieving the package of a package elemen
« Reply #4 on: June 11, 2010, 01:23:21 am »
Looping is what I currently do to get around that bug. If there's no other opinion and I haven't found myself being wrong tomorrow I'll report a bug.

b.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Retrieving the package of a package elemen
« Reply #5 on: June 11, 2010, 08:22:44 am »
The package id is available in Element.MiscData(0).

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Retrieving the package of a package elemen
« Reply #6 on: June 11, 2010, 10:23:12 am »
Quote
The package id is available in Element.MiscData(0).
Just to be clear Simon, you're saying that the Package_ID of the package that corresponds to the package element you are looking at is held in Element.MiscData(0).  The Package_ID of the containing package is in the Element.Package_ID and that (as a consequence) the Element.Parent_ID is 0.

Just as an aside, the ea_guid of both the Package and the Element is the same.

Paolo
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Retrieving the package of a package elemen
« Reply #7 on: June 11, 2010, 02:30:24 pm »
package.Element.MiscData(0) = package.PackageID
package.Element.PackageID = package.ParentID
package.Element.ParentID = 0
package.Element.ElementGUID will usually equal package.PackageGUID but this isn't required, I have seen this not be true in models predating my time at Sparx Systems.

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Retrieving the package of a package elemen
« Reply #8 on: June 11, 2010, 02:51:37 pm »
Quote
...package.PackageGUID but this isn't required, I have seen this not be true in models predating my time at Sparx Systems.
Thanks Simon,

I, too, have seen them not to be equal in some very old models (no longer in use) - and put it down to a bug.  However, not for the last many years.  I suspect (without proof) that the integrity check fixes that up.  It certainly fixes incorrect naming if the two instances: t_package and t_object have different names - so it's obviously joining on the GUID.

Could you confirm if the integrity check rectifies the inconsistent GUIDs?

Paolo
« Last Edit: June 11, 2010, 02:52:49 pm by PaoloFCantoni »
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

beginner

  • Guest
Re: Retrieving the package of a package elemen
« Reply #9 on: June 11, 2010, 04:24:42 pm »
Thanks, Simon.

However. This is inconsistent, and in no way logically. It's EAUI. It will not be rectified. I will not report a bug.

b.