Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Tom@s on May 12, 2021, 10:50:32 pm

Title: C# example code to move existing diagram to different element/package
Post by: Tom@s on May 12, 2021, 10:50:32 pm
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
                }
         }
}

Title: Re: C# example code to move existing diagram to different element/package
Post by: Geert Bellekens on May 13, 2021, 01:39:20 am
simply set the parentID of your diagram to the ElementID of the target element.

Geert
Title: Re: C# example code to move existing diagram to different element/package
Post by: Tom@s on May 13, 2021, 11:59:19 pm
Tank you Geert.

It works:
diagram.ParentID = element2.ElementID;
diagram.Update();
Title: Re: C# example code to move existing diagram to different element/package
Post by: Geert Bellekens on May 14, 2021, 01:22:55 am
Tank you Greet.

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

Geert
Title: Re: C# example code to move existing diagram to different element/package
Post by: qwerty on May 14, 2021, 02:07:38 am
Geert->Greet is nice.  Better than Geert->Gretchen.

q.