Sparx Systems Forum
Enterprise Architect => Suggestions and Requests => Topic started 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
-
The easiest way would be to call Repository.GetPackageByGuid with the guid from the element.
-
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
-
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!
-
You have to read the response carefully
It says Repository.GetPackageBy[highlight]Guid[/highlight]
GetPackageBy[highlight]ID[/highlight]
Geert
-
OOPS- thank you for conversion of my attention!
but how do I access diagramObject's GUID?
-
you first get the element using GetElementByID and then use the GUID of the element object.
Geert
-
Thanks a lot!
As you see I'm a new user of EA and this forum seems to be very helpful!
-
That won't work this way. From my Scripting book (chap 2.3)
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: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.
-
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
-
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.
-
Thank you all for quick answers!
-
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!
-
The hyperlink is a special Text element. You will find it amongst the diagramObjects.
q.
-
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???
-
I think it will be:
EA.Diagram diagram = Repository.GetDiagramById(element.MiscData(0))
-
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
-
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.
-
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