Author Topic: convert EA elements  (Read 9722 times)

Tehila1

  • EA User
  • **
  • Posts: 256
  • Karma: +0/-0
    • View Profile
convert EA elements
« 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

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8063
  • Karma: +118/-20
    • View Profile
Re: convert EA elements
« Reply #1 on: November 25, 2013, 08:26:33 am »
The easiest way would be to call Repository.GetPackageByGuid with the guid from the element.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13283
  • Karma: +556/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: convert EA elements
« Reply #2 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

Tehila1

  • EA User
  • **
  • Posts: 256
  • Karma: +0/-0
    • View Profile
Re: convert EA elements
« Reply #3 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!

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13283
  • Karma: +556/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: convert EA elements
« Reply #4 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

Tehila1

  • EA User
  • **
  • Posts: 256
  • Karma: +0/-0
    • View Profile
Re: convert EA elements
« Reply #5 on: November 25, 2013, 07:30:04 pm »
OOPS- thank you for conversion of my attention!
but how do I access diagramObject's GUID?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13283
  • Karma: +556/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: convert EA elements
« Reply #6 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

Tehila1

  • EA User
  • **
  • Posts: 256
  • Karma: +0/-0
    • View Profile
Re: convert EA elements
« Reply #7 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!

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: convert EA elements
« Reply #8 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.
« Last Edit: November 25, 2013, 11:09:06 pm by qwerty »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13283
  • Karma: +556/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: convert EA elements
« Reply #9 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

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: convert EA elements
« Reply #10 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.
« Last Edit: November 26, 2013, 09:44:15 pm by qwerty »

Tehila1

  • EA User
  • **
  • Posts: 256
  • Karma: +0/-0
    • View Profile
Re: convert EA elements
« Reply #11 on: November 26, 2013, 09:32:33 pm »
Thank you all for quick answers!

Tehila1

  • EA User
  • **
  • Posts: 256
  • Karma: +0/-0
    • View Profile
Re: convert EA elements
« Reply #12 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!

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: convert EA elements
« Reply #13 on: December 03, 2013, 08:54:24 am »
The hyperlink is a special Text element. You will find it amongst the diagramObjects.

q.

Tehila1

  • EA User
  • **
  • Posts: 256
  • Karma: +0/-0
    • View Profile
Re: convert EA elements
« Reply #14 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???