Book a Demo

Author Topic: Extracting information from class diagram with JScript  (Read 3843 times)

MrSnow

  • EA User
  • **
  • Posts: 20
  • Karma: +1/-0
    • View Profile
Extracting information from class diagram with JScript
« on: March 01, 2019, 06:30:36 pm »
Hi,

I am trying to extract enough information from a class diagram in EA to create a JSON Schema for that diagram. I am able to obtain the number of classes in the diagram, but when I iterate through those classes and try to fetch "currentClass.Name" I get "undefined". Can someone help me understand what I am misunderstanding here:

"var thePackage as EA.Package.;
   thePackage = Repository.GetTreeSelectedPackage();
   
   if ( thePackage != null && thePackage.ParentID != 0 ){
      
      var diagrams as EA.Collection;
      diagrams = thePackage.Diagrams;
      
      //Navigate the diagram(s) in the current package
      for (var i = 0; i < diagrams.Count; i++)
      {
         var currentDiagram as EA.Diagram;
         currentDiagram = diagrams.GetAt(i);
         
         Session.Output("Diagram Name: " + currentDiagram.Name);
         Session.Output("Diagram Element Count: " + currentDiagram.DiagramObjects.Count);
         
         var classes as EA.Collection;
         classes = currentDiagram.DiagramObjects;
         
         for (var j = 0; j < classes.Count; j++)
         {
            var currentClass as EA.Element;
            currentClass = classes.GetAt(j);
            
            Session.Output("Class: " + currentClass.Name);
         }
      }
      
   }
"

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Extracting information from class diagram with JScript
« Reply #1 on: March 01, 2019, 07:36:49 pm »
You don't get elements but diagramObjects. Retrieve the elementId from the latter and fetch the element with Repository.GetElementByID

q.

MrSnow

  • EA User
  • **
  • Posts: 20
  • Karma: +1/-0
    • View Profile
Re: Extracting information from class diagram with JScript
« Reply #2 on: March 01, 2019, 08:04:34 pm »
You don't get elements but diagramObjects. Retrieve the elementId from the latter and fetch the element with Repository.GetElementByID

q.

Ah, thanks a lot! It worked!