Book a Demo

Author Topic: C# example code to move existing diagram to different element/package  (Read 3641 times)

Tom@s

  • EA Novice
  • *
  • Posts: 10
  • Karma: +0/-0
    • View Profile
Hi there,
here is the situation: Diagram1 is a child diagram under Element1. I need to move diagram1 as a child diagram under element2. Element1 and Elemnt2 are in the same package.

I found out clone() function is key but I'm not sure how to transfer object to new EA.Collection.

Could somebody please provide an example in C#?


Here I is my piece of code where I need move diagram:
EA.Collection elements = package.Elements;
EA.Diagram diagramToMove;
EA.Element element1;
EA.Element element2;

foreach (EA.Element element in elements){

         if (element.Stereotype == "CollaborationModel"){
                    EA.Collection diagrams = element.Diagrams;
                   
                    foreach (EA.Diagram diagram in diagrams){
                       if (diagram.Stereotype == "CollaborationModel"){
                            diagramToMove = diagram;
                            //when I move diagram under new element then the diagram should be somehow deleted from original diagrams collection.
                        }
                    }
         }
         if (element.Stereotype == "BusinessProcess"){
                   element2 = element;
                   EA.Collection element2Diagrams = element2.Diagrams;
                   //here i need to add existing diagramToMove as a child diagram to element2
                }
         }
}


Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
simply set the parentID of your diagram to the ElementID of the target element.

Geert

Tom@s

  • EA Novice
  • *
  • Posts: 10
  • Karma: +0/-0
    • View Profile
Tank you Geert.

It works:
diagram.ParentID = element2.ElementID;
diagram.Update();
« Last Edit: May 14, 2021, 05:54:55 pm by Tom@s »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Tank you Greet.

It works:
diagram.ParentID = element2.ElementID;
diagram.Update();
You're welcome Mot@s ;)

Geert

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Geert->Greet is nice.  Better than Geert->Gretchen.

q.