Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: iwt2 on August 04, 2010, 12:04:25 am

Title: Any idea to do this directly?
Post by: iwt2 on August 04, 2010, 12:04:25 am
Hello everyone,

I have a question:

From a Package object (a row of t_package table) I can find the Element object (a row of  t_object table) associated.

But from an Element object, can I find directly the object associated Package? A database level know how to find it: if the element is of type package, I have only to look at the field PDATA1 to know the id of the associated package (Table t_package). But I need to do it with the methods of the api.

Any idea to do it directly?

Thank you very much.
Title: Re: Any idea to do this directly?
Post by: peuhhhh on August 04, 2010, 12:07:53 am
hello iwt2,
did u try :
Code: [Select]
Repository.GetPackageByID(YourElement.PackageID) ;
?

Title: Re: Any idea to do this directly?
Post by: iwt2 on August 04, 2010, 12:27:33 am
Quote
hello iwt2,
did u try :
Code: [Select]
Repository.GetPackageByID(YourElement.PackageID) ;
?


      
that's not what I need. This instruction returns the package where the element is.

As you know, when you create a package, EA generates two records: one at the t_object table  and  other  at the t_package table. both are related through the field  PDATA1 of  the t_object table.
 

I need to find the package (Table t_package) from element (table t_objec) using the API methods.

other  idea?
Title: Re: Any idea to do this directly?
Post by: Paolo F Cantoni on August 04, 2010, 12:58:24 am
The t_package and t_object items for the same package share the same GUID so you would use:

Repository.GetPackageByGuid(MyPackageElement.ElementGuid);
or in the other direction:
Repository.GetElementByGuid(MyPackage.PackageGuid);

HTH,
Paolo
Title: Re: Any idea to do this directly?
Post by: «Midnight» on August 04, 2010, 02:41:12 am
For that matter, as long as you only need to read (not change) the ID, you can retrieve the PDATA1 field via the API. Element.MiscData(0) will return the contents of PDATA1.

The catch is that this is a read only value. You cannot directly manipulate the PDATA fields through the MiscData fields.
Title: Re: Any idea to do this directly?
Post by: iwt2 on August 04, 2010, 04:17:00 am
great! just what I needed  :D.

thank you very much everybody.