Book a Demo

Author Topic: Copy Package, Diagram, Element in C#  (Read 4297 times)

Tom@s

  • EA Novice
  • *
  • Posts: 10
  • Karma: +0/-0
    • View Profile
Copy Package, Diagram, Element in C#
« on: May 19, 2021, 09:07:00 pm »
Hello,
In some cases, I need to copy element or diagram or package.
Copy explanation:
  • element - fullstructure copy
  • package - fullstructure copy
  • package - copy just a diagram (I don't want to copy elements used in the diagram)

If I understood right there is only one way to do it - use cloning function.


//test fullstructure copy for package
EA.Package clonedPackage = subPackage.Clone();
clonedPackage.Name = clonedPackage.Name + "_Copy";
clonedPackage.ParentID = rootPackage.PackageID;
clonedPackage.Update();
subPackages.Refresh();
rootPackage.Update();

The documentation says about the package clone function: "Inserts a copy of the Package into the same parent as the original Package. Returns the newly-created Package"
I couldn't see a new package so I decided to set parent ID but it didn't work either.

Could you please help me to create copy for package, element, diagram?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Copy Package, Diagram, Element in C#
« Reply #1 on: May 19, 2021, 09:14:32 pm »
You don't need the last two lines

Code: [Select]
subPackages.Refresh();
rootPackage.Update();

What is the root package packageID? With "root" to you mean really root? Because they behave a bit different.

Make sure to reload the model. That might be preventing you from seeing the cloned package.

Geert

Tom@s

  • EA Novice
  • *
  • Posts: 10
  • Karma: +0/-0
    • View Profile
Re: Copy Package, Diagram, Element in C#
« Reply #2 on: May 19, 2021, 09:18:31 pm »
Root package is selected package in EA. I had a bug in code - I fixed it and now cloning works perfectly for package and elements.(Thank you Geert)

What about diagrams? Is there some way how to make a copy? (Copy just the diagram - I don't want to copy elements used in the diagram. Function in EA is called Type of Copy -> Shallow - links to existing elements)
« Last Edit: May 19, 2021, 09:44:23 pm by Tom@s »