0
votes

I'm working on a very large UML documentation project for my company. We are trying to model an existing program in Enterprise Architect to better document it. Due to the size of the application, we have chosen to break up the diagrams into separate packages within the main package (such as GUI, GPS, Removable Media, etc). This works great for the individual class diagrams of each part. However, I would like to drag and drop the class diagrams over from each package to a master diagram to show how they all connect as a system.

Is it possible to write a scripting function to take the linked diagrams and automatically link them all similarly to how the code engineering import does? I noticed in the last step of the code import it adds the associations and generalizations. I figured if Sparx can do it when importing the code, I should be able to link them afterwards in my master document. Any ideas on how to achieve this?

If not possible, is there a way to link the created diagrams from the code engineering to the ones that are already existing in my packages? I think it would be useful to be able to right click a class diagram and "find in packages" from the master document to see more details.

1

1 Answers

1
votes

What you will basically do is to create an overview diagram and just drag and drop the relevant diagram from the browser. This offers a selection box

enter image description here

where you just leave the first selection Diagram Frame. EA will create a new object with a name suggested from the diagram name (you can leave that but also change it if you have a need for that). Now the dragged diagram will appear inside a named frame on the overview diagram. You can not scale this diagram, so it will have the size of the original one plus the frame around it.

Note: you can use Hyperlink in the above dialog to create nice and short links between diagrams for navigation.

Now for the scripting part. I will use a meta language, but you will likely guess how to use it in your preferred language. The first thing is to locate the overview diagram. You can query its diagram guid by right-clicking it in the browser and using Copy/Copy Node GUID.... Now with that id you can locate it by (example guid below):

overview = rep.GetDiagramByGUID("{A006B95E-1237-4778-A339-D1B407C6FD5C}")

Next is to locate the single diagrams you want to show on the overview. This is up to you how to find them. Eventually they will be at certain locations in the repository. To statically load the first diagram in the first package in the first view of the first root you would call

model = repository.Models.GetAt(0)
view = model.Packages.GetAt(0)
package1 = view.Packages.GetAt(0)
dia1 = package1.Diagrams.GetAt(0)

You will likely use smarter ways to iterate and find the relevant diagrams.

Now with these diagram objects at hand you can create the diagram frame. This needs to be placed somewhere in a package. For simplicity I use package1 but you will eventually place them in the package of the overview diagram.

frame = package1.Elements.AddNew(dia1.Name, "UMLDiagram")
frame.Update()
sql = "UPDATE t_object SET PDATA1=" + str(dia1.DiagramID) + " WHERE Object_ID=" + str(overview.diagramID
repository.Execute(sql)

This is voodoo, I know. The API does not offer a way to link the UMLDiagram element with the referenced diagram. So this must be poked into the database directly.

Finally, the newly created frame object can be placed in the overview diagram:

diagramObj = overview.DiagramObjects.AddNew("l=10;r=110;t=-20;b=-80","")
diagramObj.ElementID = frame.ElementID
diagramobj.Update()

Since this EA, the coordinates for the y-axis are towards negative from the top (l, r, t, b stand for, guess). EA will expand he frame to the minimum above the specified size.

In order to see the result you need to close/open the overview diagram. I will leave that as exercise to you :-)