Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started 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
}
}
}
-
simply set the parentID of your diagram to the ElementID of the target element.
Geert
-
Tank you Geert.
It works:
diagram.ParentID = element2.ElementID;
diagram.Update();
-
Tank you Greet.
It works:
diagram.ParentID = element2.ElementID;
diagram.Update();
You're welcome Mot@s ;)
Geert
-
Geert->Greet is nice. Better than Geert->Gretchen.
q.