enterprise-architect

Moving diagrams between projects in enterprise architect


I have a project with several diagrams (with elements). I want to close this particular project and move the diagrams to other more suitable projects.

Moving a diagram is simple. Problem is that now I have to manually find all related element to this particular diagram and move them one by one to the other project. As I have quite a few elements in all diagrams in the original project this is quite tedious.

I wonder if there's an easier way of handling refactoring like this in EA?


Solution

  • There is no easier way in out-of-the-box EA, no. But where there's a will there's a way.

    First off, make a copy of your project. The solution I'm describing will destroy its structure.

    Second, create an empty package and move the diagram there.

    Third, create a VBScript in the Browserscript group (Tools - Scripting). Call it "Collect Diagram Elements". In the editor, replace the commented-out otDiagram case with the following:

    case otDiagram
        ' Code for when a diagram is selected
        dim theDiagram as EA.Diagram
        set theDiagram = Repository.GetTreeSelectedObject()
        dim dObj as EA.DiagramObject
        dim element as EA.Element
        for each dObj in theDiagram.DiagramObjects
            set element = Repository.GetElementByID(dObj.ElementID)
            element.PackageID = theDiagram.PackageID
            element.Update()
        next
    

    This script runs through all the elements shown in a diagram and moves them to the package the diagram is in.

    Run the script by right-clicking the diagram in the package browser and selecting Scripts - Collect Diagram Elements. After the script finishes, you may need to reload the package (right-click the package in the package browser, select Contents - Reload Current Package).

    Finally, export the package to XMI (right-click in the package browser, select Import/Export - Export Package to XMI File), and then import it into your target project.