Author Topic: How to add an element into an another using AI s..  (Read 2817 times)

patson

  • EA Novice
  • *
  • Posts: 9
  • Karma: +0/-0
    • View Profile
How to add an element into an another using AI s..
« on: May 06, 2010, 11:06:36 am »
Hi all,
I am working on add-in and I have to do the following.
first I have to select an element (element1 from type Class) from a project browser and create a subdiagram ("NewDiagram") to this element. Then I have to copy a link to  "element1" into the subdiagram. so far it is good.
secondly I have to create a new element (element2 from type Class) and add them into "NewDiagram" such that "element2" is always in front of(also it is fix to ) "element1" when moving "element1" in the diagram.
Manually the second element is automatically in front of the first element or it can be do by applying Z-Order -> Bring forward to "element2". But when I do it with the Automation Interface, "element1" is always fix to "element2" although I want to have the contrary.
I will be very grateful when someboy can help me

Regards

my code

                    EA.ObjectType obt = Repository.GetTreeSelectedItemType();
                    if(obt != ObjectType.otElement)
                    {
                        MessageBox.Show("Please select an element in the project browser");
                        return;
                    }

                    Object obj = Repository.GetTreeSelectedObject();
                    EA.Element element1 = (EA.Element)obj;

                    // attach a subdiagram to the selected element
                    EA.Collection collectionSubDiag = element1.Diagrams;
                    Object obj3 = collectionSubDiag.AddNew("NewDiagram", "Logical");
                    EA.Diagram diagram = (EA.Diagram)obj3;
                    diagram.Update();
                    collectionSubDiag.Refresh();

                    // create a link to the selected element in NewDiagram.
                    EA.Collection collectionDiagramObjects = diagram.DiagramObjects;

                    Object obj5 = collectionDiagramObjects.AddNew("", "");
                    EA.DiagramObject dobj5 = (EA.DiagramObject)obj5;
                    dobj5.ElementID = element1.ElementID;
                    dobj5.Update();
                    collectionDiagramObjects.Refresh();

                    Repository.RefreshOpenDiagrams(true);
                    Repository.ReloadDiagram(diagram.DiagramID);
                    Repository.OpenDiagram(diagram.DiagramID);

                    // create a new element "element2" and add it to "NewDiagram" such that
                    // "element2" is always fix (in front) to "element1" when moving "element1"
                    // manually it is do with Z-order -> Bring forward.

                    EA.Collection collectionChildElem = element1.Elements;
                    Object obj2 = collectionChildElem.AddNew("newElement", "Class");
                    EA.Element element2 = (EA.Element)obj2;
                    element2.ParentID = element1.ElementID;
                    element2.Stereotype = "Failure";
                    element2.Update();
                    collectionChildElem.Refresh();

                    // Add "element2" to "NewDiagram"
                    Object obj4 = collectionDiagramObjects.AddNew("", "");
                    EA.DiagramObject dobj4 = (EA.DiagramObject)obj4;
                    dobj4.ElementID = element2.ElementID;
                    dobj4.Update();
                    collectionDiagramObjects.Refresh();


                    Repository.RefreshOpenDiagrams(true);
                    Repository.ReloadDiagram(diagram.DiagramID);
                    Repository.OpenDiagram(diagram.DiagramID);

Martin Walke

  • EA User
  • **
  • Posts: 51
  • Karma: +0/-0
    • View Profile
Re: How to add an element into an another using AI
« Reply #1 on: May 07, 2010, 02:01:48 am »
Hi,

Have a look at the Sequence property of a DiagramObject. May do what you need.

HTH
Martin

patson

  • EA Novice
  • *
  • Posts: 9
  • Karma: +0/-0
    • View Profile
Re: How to add an element into an another using AI
« Reply #2 on: May 07, 2010, 05:35:05 am »
Hi Martin,

it work with the sequence attribut of diagramObject. The element to be fix must have a lower Sequence value.

Thanks for the Help
Regards

Joe

Martin Walke

  • EA User
  • **
  • Posts: 51
  • Karma: +0/-0
    • View Profile
Re: How to add an element into an another using AI
« Reply #3 on: May 07, 2010, 06:03:20 pm »
Glad to be of help. I'm a fairly newbie myself so I know what it's like! ;)