Book a Demo

Author Topic: How do I get an element from the diagram  (Read 5358 times)

marine1981

  • EA User
  • **
  • Posts: 58
  • Karma: +0/-0
    • View Profile
How do I get an element from the diagram
« on: March 23, 2011, 07:44:49 pm »
Hello,
How do I get an element from the diagram?
My first Idea:
Code: [Select]
for ( var j = 0; j < diagrams.Count; j++ )
{
  currentDiagram = diagrams.GetAt( j );
  if (currentDiagram.Type == "Activity")
  {
   //Count Elements in the Diagram!
   Session.Output(currentDiagram.DiagramObjects.Count);
   for( var k = 0; k < currentDiagram.DiagramObjects.Count; k++ )
   {
   //Question: How do I get an element from the diagram?
      
   }
}


Thanks


Sven

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: How do I get an element from the diagram
« Reply #1 on: March 23, 2011, 09:15:07 pm »
Each diagram object has an element_id which can be retrieved from the repository via getElementById

q.

marine1981

  • EA User
  • **
  • Posts: 58
  • Karma: +0/-0
    • View Profile
Re: How do I get an element from the diagram
« Reply #2 on: March 23, 2011, 10:34:56 pm »
It does not work with the element ID. I don't know the elementID because I have got some elements in the diagram. I know only the elementtype. One element in the diagram is a Requirement or later a activity.

stao

  • EA User
  • **
  • Posts: 137
  • Karma: +0/-0
    • View Profile
Re: How do I get an element from the diagram
« Reply #3 on: March 24, 2011, 06:38:33 am »
i dont really know what you actual want to achieve.

PS. you can PM me in german.
i m rly sure we can solve your problem.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: How do I get an element from the diagram
« Reply #4 on: March 24, 2011, 03:13:40 pm »
If you want to know anything (except for maybe color and position) about an element on a diagram you'll have to get that element first.
So that would become something like:
Code: [Select]
for ( var j = 0; j < diagrams.Count; j++ )
{
 currentDiagram = diagrams.GetAt( j );
 if (currentDiagram.Type == "Activity")
 {
  //Count Elements in the Diagram!
  Session.Output(currentDiagram.DiagramObjects.Count);
  for( var k = 0; k < currentDiagram.DiagramObjects.Count; k++ )
  {
  EA.DiagramObject myDiagramObject = (EA.DiagramObject) currentDiagramObject.getAt(k);
  EA.Element myElement = myRepository.getElementByID(myDiagramObject.ElementID);
  if (myElement.Type == "Requirement")
   { //Now you do something...}
      
  }
}

PS. Looping an EA.Collection with a foreach iso a for is often a lot easier on the eye.

Geert

marine1981

  • EA User
  • **
  • Posts: 58
  • Karma: +0/-0
    • View Profile
Re: How do I get an element from the diagram
« Reply #5 on: March 24, 2011, 06:28:14 pm »
Thanks Geert. Now, I develop a Script with JScript. It is a validation script.