Sparx Systems Forum

Enterprise Architect => Suggestions and Requests => Topic started by: Tehila1 on November 25, 2013, 12:26:22 am

Title: convert EA elements
Post by: Tehila1 on November 25, 2013, 12:26:22 am
Hello everybody!
I want to convert programmatically EA.Element which its type is Package, to EA.Package.
Any Idea?

Thanx
Title: Re: convert EA elements
Post by: Eve on November 25, 2013, 08:26:33 am
The easiest way would be to call Repository.GetPackageByGuid with the guid from the element.
Title: Re: convert EA elements
Post by: Geert Bellekens on November 25, 2013, 06:20:48 pm
There should be no need for any conversion at all.
For each EA.Element with type 'Package' there exists a EA.Package equivalent.

Use the method suggested by Simon to get the corresponding object.

Geert
Title: Re: convert EA elements
Post by: Tehila1 on November 25, 2013, 06:51:59 pm
Hello!
Thanks for quick reply!
I'm still stuck with that issue:
I want to loop on all diagram element. This diagram is an owner of only packages. I want to refer the elements like packages:

foreach (EA.DiagramObject curElement in selectedDiagram.DiagramObjects)
                  {
                  int packageID=curElement.ElementID;
                  EA.Package package= Repository.GetPackageByID(packageID);
                  }

I accept this message :"Can't find matching ID" :(

Thanks in advance!
Title: Re: convert EA elements
Post by: Geert Bellekens on November 25, 2013, 06:59:36 pm
You have to read the response carefully

It says Repository.GetPackageBy[highlight]Guid[/highlight]

GetPackageBy[highlight]ID[/highlight]

Geert
Title: Re: convert EA elements
Post by: Tehila1 on November 25, 2013, 07:30:04 pm
OOPS- thank you for conversion of my attention!
but how do I access diagramObject's GUID?
Title: Re: convert EA elements
Post by: Geert Bellekens on November 25, 2013, 09:14:53 pm
you first get the element using GetElementByID and then use the GUID of the element object.

Geert
Title: Re: convert EA elements
Post by: Tehila1 on November 25, 2013, 09:48:02 pm
Thanks a lot!
As you see I'm a new user of EA and this forum seems to be very helpful!
Title: Re: convert EA elements
Post by: qwerty on November 25, 2013, 11:03:14 pm
That won't work this way. From my Scripting book (chap 2.3)
Quote
If you issue

  package = Repository.GetPackageByID (package_element.PackageID);

then package will be Modeling Basics (which is likely not what you would expect) while

  package = Repository.GetPackageByID (package_element.MiscData(0));

will make package to be Line Styles. Note that the expected integer value might need a cast
from string in your programming language.

Your GetElementByID will get the package_element related to the package. So try:
Code: [Select]
foreach (EA.DiagramObject curElement in selectedDiagram.DiagramObjects)
                 {
                 int packageID=curElement.ElementID;
                 EA.Element element = Repository.GetElementByID(packageID);
                 EA.Package package= Repository.GetPackageByID(element.MiscData[0]);
                 }

(I have no idea how to address the first element of the array MiscData in the language you use.)

q.
Title: Re: convert EA elements
Post by: Geert Bellekens on November 26, 2013, 06:08:27 pm
Q,

It should also work that way. You can verify yourself, the row in t_object has the same ea_guid as the row in t_package.

I just realized that a few days ago myself, because that is a lot easier then having to use the pdata1, casting to integer etc...
I'm not sure why we have been using that method for years now when there's a much easier alternative.

Geert
Title: Re: convert EA elements
Post by: qwerty on November 26, 2013, 09:03:44 pm
Ah! i was not aware of that. Thanks a bunch, Geert  :)

We've probably used that after I had asked Sparx how to do it. And that was their suggestion. Now, why are there two ways to do it? Who designed that? I will not ask :-X

q.
Title: Re: convert EA elements
Post by: Tehila1 on November 26, 2013, 09:32:33 pm
Thank you all for quick answers!
Title: Re: convert EA elements
Post by: Tehila1 on December 02, 2013, 09:03:29 pm
Hello!

I want to access programmatically classes which are owned by a diagram via a hyperlink for that diagram.
Is there an existing way to do so, or I must convert the diagram hyperlink to a regular diagram?

Thank you!
Title: Re: convert EA elements
Post by: qwerty on December 03, 2013, 08:54:24 am
The hyperlink is a special Text element. You will find it amongst the diagramObjects.

q.
Title: Re: convert EA elements
Post by: Tehila1 on December 03, 2013, 09:59:16 pm
Yes- The diagram hyperlink is a member of the diagram objects.
But, in order to access the 'Text' element we ought to convert it to EA.Diagram object.
Well- I did it like this:

foreach(EA.DiagramObject diagramObject in diagram.DiagramObjects)
                        {
EA.Element element= Repository.GetElementByID(diagramObject.ElementID);
}

Now. I would like to get the appropriate EA.Diagram
EA.Diagram diagram=Repository.GetDiagramByGuid(element.ElementGUID);
 but the diagram's GUID is different from the element's GUID. and an error was occurred: "Can't find matching ID"  :(

So how can I do it???
Title: Re: convert EA elements
Post by: KP on December 04, 2013, 08:55:34 am
I think it will be:

EA.Diagram diagram = Repository.GetDiagramById(element.MiscData(0))
Title: Re: convert EA elements
Post by: Geert Bellekens on December 04, 2013, 05:45:48 pm
Quote
I think it will be:

EA.Diagram diagram = Repository.GetDiagramById(element.MiscData(0))

No that won't work. The element doesn't know which diagrams it is used on.

But this question is getting a bit silly.
You start from a diagram object, then loop all diagramObjects and get their element object, then then you try get get the diagram agaain? But you already have that object?

I'm confused :-?

Geert
Title: Re: convert EA elements
Post by: qwerty on December 04, 2013, 05:48:42 pm
KP is correct, Geert. The Hyperlink element has the linked diagram in MiscData(0).

Honestly, I was confused the same way as you first.

q.
Title: Re: convert EA elements
Post by: Geert Bellekens on December 04, 2013, 05:51:37 pm
Quote
KP is correct, Geert. The Hyperlink element has the linked diagram in MiscData(0).

Honestly, I was confused the same way as you first.

q.
Ah now I see. I missed the fact that we were talking about a hyperlink element. :-[

Geert