Book a Demo

Author Topic: How I get the main/first element in a diagram?  (Read 6102 times)

marine1981

  • EA User
  • **
  • Posts: 58
  • Karma: +0/-0
    • View Profile
How I get the main/first element in a diagram?
« on: November 26, 2010, 02:06:25 am »
I want connect two elements. Later I want conntect further elements with the main element. How I get the elementID from the first/main element in the diagram?                        
                        
                        
                        
Code: [Select]
public bool AutoIntegrationElement(EA.Repository Repository,EA.Package ParentPackage, EA.Element NewElement)
{
  if (ParentPackage.Diagrams.Count == 1)
  {
      //it exist only one diagram
      EA.Diagram ParentDiagram = (EA.Diagram)ParentPackage.Diagrams.GetAt(0);
      EA.DiagramObject ParentDiagramObject = (EA.DiagramObject)ParentDiagram.DiagramObjects.AddNew("", "");
      ParentDiagramObject.ElementID = NewElement.ElementID;
      ParentDiagramObject.Update();            
      //my problem begins here: How I get the main/first Element of the Diagram?
      EA.Connector newCon = (EA.Connector)ownerElement.Connectors.AddNew("testlink", "Association");
      newCon.SupplierID = myDiagramObject.ElementID;
      newCon.Update();
      //------------------------------------------------------------
      //After then, I want layout the diagram
      //------------------------------------------------------------
     //How I use the Method:
     //"LayoutDiagramEx(string DiagramGUID, long LayoutStyle, long Iterartions, long ColumnSpacing, boolean SaveToDiagram);
     return true;
     }
return false;
}
                        
Have got anyone a idea?

Thanks


Sven

stao

  • EA User
  • **
  • Posts: 137
  • Karma: +0/-0
    • View Profile
Re: How I get the main/first element in a diagram?
« Reply #1 on: November 26, 2010, 04:50:41 am »
i think there is no possibility to set an element always as the first one in the diagram.elements collection ( think they are sorted by name ).
i would "mark" my main element by name or by a custom stereotype to identify it as the main element

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 I get the main/first element in a diagram?
« Reply #2 on: November 26, 2010, 05:02:15 pm »
Sven,

You'll have to think like: "how do I know which the first/main object in my diagram is".
If you can answer that question then you can make your addin follow the same logic.

Geert

marine1981

  • EA User
  • **
  • Posts: 58
  • Karma: +0/-0
    • View Profile
Re: How I get the main/first element in a diagram?
« Reply #3 on: November 26, 2010, 05:35:59 pm »
The first element is well-defined becaus the main/first element has got a clear stereotype. The other elements in the diagram have got the same stereotype.
My question should called:
  • How I can get the elements in the diagram
  • How I can compare the diagrams with the stereoype(foreach)?"
Do you got have any idea?
« Last Edit: November 26, 2010, 05:36:20 pm by marine1981 »

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 I get the main/first element in a diagram?
« Reply #4 on: November 26, 2010, 06:07:23 pm »
you mean like this:
Code: [Select]
       public EA.Element getMainElement(EA.Diagram diagram, EA.Repository repository)
        {
            foreach (EA.DiagramObject diagramObject in diagram.DiagramObjects)
            {
                try
                {
                    EA.Element currentElement = repository.GetElementByID(diagramObject.ElementID);
                    if (currentElement.Stereotype == string.Empty)
                    {
                        return currentElement;
                    }
                }
                catch (COMException)
                {
                    // element not found, continue with next, nothing to do.
                }
            }
            // in case nothing was found, return null
            return null;
        }

Geert

marine1981

  • EA User
  • **
  • Posts: 58
  • Karma: +0/-0
    • View Profile
Re: How I get the main/first element in a diagram?
« Reply #5 on: November 26, 2010, 06:57:03 pm »
Thank you. This sourcecode was very helpful!!!

marine1981

  • EA User
  • **
  • Posts: 58
  • Karma: +0/-0
    • View Profile
Re: How I get the main/first element in a diagram?
« Reply #6 on: November 26, 2010, 07:26:34 pm »
Now, my last question(I hope it).
How I can use:
Code: [Select]
LayoutDiagramEx(string DiagramGUID, long LayoutStyle, long Iterartions, long ColumnSpacing, boolean SaveToDiagram);My first idea was
ParentDiagram.DiagramObjects.LayoutDiagramEx(...)
But LayoutDiagram isn't a member of DiagramObjects. Where I can find that Method?
How I can define a connecttype composition? I can only find association, ... but not a composition.
« Last Edit: November 26, 2010, 07:37:44 pm by marine1981 »

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 I get the main/first element in a diagram?
« Reply #7 on: November 26, 2010, 07:55:43 pm »
look here: http://www.sparxsystems.com/enterprise_architect_user_guide/automation_and_scripts/project_2.html
you can get the Project Interface from Repository.

Geert

marine1981

  • EA User
  • **
  • Posts: 58
  • Karma: +0/-0
    • View Profile
Re: How I get the main/first element in a diagram?
« Reply #8 on: November 26, 2010, 08:47:37 pm »
It does everythink work, now!

LayoutDiagramEx is only testing the parameters like "try and trash". :-)