Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: minna on February 28, 2014, 11:59:35 pm
-
Hi,
I has 3 classes in my diagram. I have a list of connectors in Excel. I want to add these connectors to EA automatically. I found an article to assist me with adding the relevant code to Excel:
http://www.sparxsystems.com/enterprise_architect_user_guide/9.2/automation/addaconnector.html
To use this code, I need the ElementIDs of my classes. So I wrote the following script in EA.
var currentPackage as EA.Package;
currentPackage = Repository.GetTreeSelectedPackage();
var packageDiagrams as EA.Collection;
packageDiagrams = currentPackage.Diagrams;
var myObjects as EA.Collection;
var currentDiagram as EA.Diagram;
var currentObject as EA.DiagramObject;
for ( var i = 0 ; i < packageDiagrams.Count ; i++ )
{
currentDiagram = packageDiagrams.GetAt(i);
myObjects = currentDiagram.DiagramObjects;
for ( var j = 0 ; j < myObjects.Count ; j++ )
{
currentObject = myObjects.GetAt(j);
Session.Output( "ElementID: " + currentObject.ElementID);
Session.Output( "ElementGUID: " + currentObject.ElementGUID);
}
}
My question is, how do I display the element name or GUID to make sure I have the correct elements ("Class1", "Class2" and "Class3)? When running the above code, Session.Output( "ElementGUID: " + currentObject.ElementGUID); returns undefined.
Thanks,
Minna
-
You may need the actual element to get GUID information..
Try This
var currentPackage as EA.Package;
currentPackage = Repository.GetTreeSelectedPackage();
var packageDiagrams as EA.Collection;
packageDiagrams = currentPackage.Diagrams;
var myObjects as EA.Collection;
var currentDiagram as EA.Diagram;
var currentObject as EA.DiagramObject;
for ( var i = 0 ; i < packageDiagrams.Count ; i++ )
{
currentDiagram = packageDiagrams.GetAt(i);
myObjects = currentDiagram.DiagramObjects;
for ( var j = 0 ; j < myObjects.Count ; j++ )
{
currentObject = myObjects.GetAt(j);
var obj as EA.Element;
obj = Repository.GetElementByID(currentObject.ElementID);
if (obj)
{
Session.Output( "ElementID: " + obj.ElementID);
Session.Output( "ElementGUID: " + obj.ElementGUID);
}
}
}
-
It is really important to get debugging working in EA or in Visual Basic. That way you can set a break point where it normally crashes, and step into and see the actual object structure.
My guess is that you are possibly grabbing some other items that are in the diagram as well. I think things like notes or other elements that aren't first class model citizens will still be diagram objects, but may not have an elementID.
I have a line in my powerpoint tool (If (theDiagramFrame.ObjectType = 19)) that looks for specific types of diagramobjects. I believe I had to find out the actual number associated with the object type through debugging because I couldn't find the documentation on it. So you need to either look for something specific, or filter out the items in the diagram that aren't considered elements.
-
Nizam spotted the missing statements in minna's code...
q.
-
Thank you!