Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: minna on February 28, 2014, 11:59:35 pm

Title: EA Scripting and importing connectors from Excel
Post 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.

Code: [Select]
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
Title: Re: EA Scripting and importing connectors from Exc
Post by: Nizam Mohamed on March 01, 2014, 01:15:23 am
You may need the actual element to get GUID information..

Try This
Code: [Select]
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);
                  }
            }
      }
Title: Re: EA Scripting and importing connectors from Exc
Post by: rothnic on March 04, 2014, 05:06:39 am
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.
Title: Re: EA Scripting and importing connectors from Exc
Post by: qwerty on March 04, 2014, 05:24:38 am
Nizam spotted the missing statements in minna's code...

q.
Title: Re: EA Scripting and importing connectors from Exc
Post by: minna on March 17, 2014, 08:49:09 pm
Thank you!