Book a Demo

Author Topic: getting Details of a Linked Elements on a Diagram  (Read 2961 times)

tria1312

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
getting Details of a Linked Elements on a Diagram
« on: February 08, 2012, 06:26:30 pm »
Hi all,

I want to get details of the element found on a diagram. These elements are not all in the same package.

With the code below I am able to get the list of objects which are located on the diagram. The amount and the Element-IDs of the objects are OK, but I can't get the name and the type of them.
What is the trick to get also these information?


Best regards
tria1312
 

Code: [Select]
function DumpDiagrams(indent, thePackage)
{
      // Cast thePackage to EA.Package so we get intellisense
      var currentPackage as EA.Package;
      currentPackage = thePackage;
      
      // Iterate through all diagrams in the current package
      var diagramEnumerator = new Enumerator( currentPackage.Diagrams );
      while ( !diagramEnumerator.atEnd() )
      {
            var currentDiagram as EA.Diagram;
            currentDiagram = diagramEnumerator.item();
            var diagramObjects as EA.Collection;
            diagramObjects = currentDiagram.DiagramObjects;
            
            // Add the current package's name to the list
            Session.Output(indent + "::" + currentDiagram.Name +
                  " (DiagramID = " + currentDiagram.DiagramID + ")" + " Elements on Diagram = " + currentDiagram.DiagramObjects.Count);
            
            // Iterate through all elements and add them to the list
            var elementEnumerator = new Enumerator(currentDiagram.DiagramObjects);
            while(!elementEnumerator.atEnd())
            {
                  var currentElement as EA.Element;
                  currentElement = elementEnumerator.item();
                  
                  Session.Output(indent + "::" + currentElement.Name +
                        " (" + currentElement.Type +
                        ", ID=" + currentElement.ElementID + ")");
                  
                  elementEnumerator.moveNext();
            }

            diagramEnumerator.moveNext();
      }
}


Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: getting Details of a Linked Elements on a Diag
« Reply #1 on: February 08, 2012, 06:39:56 pm »
An EA.DiagramObject is not an EA.Element.
In order to get the EA.Element from the EA.DiagramObject you need to use Repository.GetElementByID (long ElementID)

Geert

tria1312

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: getting Details of a Linked Elements on a Diag
« Reply #2 on: February 08, 2012, 07:36:22 pm »
Hi,

so I tried to change my code to use the objects like this:
Code: [Select]
function DumpDiagrams(indent, thePackage)
{
      // Cast thePackage to EA.Package so we get intellisense
      var currentPackage as EA.Package;
      currentPackage = thePackage;
      
      // Iterate through all diagrams in the current package
      var diagramEnumerator = new Enumerator( currentPackage.Diagrams );
      while ( !diagramEnumerator.atEnd() )
      {
            var currentDiagram as EA.Diagram;
            currentDiagram = diagramEnumerator.item();
            var diagramObjects as EA.Collection;
            diagramObjects = currentDiagram.DiagramObjects;
            
            // Add the current package's name to the list
            Session.Output(indent + "::" + currentDiagram.Name +
                  " (DiagramID = " + currentDiagram.DiagramID + ")" + " Elements on Diagram = " + currentDiagram.DiagramObjects.Count);
                        
            // Iterate through all elements and add them to the list
            var elementEnumerator = new Enumerator(currentDiagram.DiagramObjects);
            while(!elementEnumerator.atEnd())
            {
                  var eaElement as EA.Element;
                  eaElement = Repository.GetElementByID(elementEnumerator.item().ElementID);
                  
                  Session.Output(indent + "::" + eaElement.Name +
                        " (" + eaElement.Type +
                        ", ID=" + eaElement.ElementID + ")");
                  
                  elementEnumerator.moveNext();
            }

            diagramEnumerator.moveNext();
      }
}

THX!  :)


Best regards
tria1312