Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Andre_b_b on July 04, 2023, 12:12:17 am
-
Hi guys, i am able to add packages to a model, add diagrams and elements to a package, add elements do diagram and connectors between the elements. Almost perfect, except for the fact that when i finish running my script, the elements are all in the same position and the layout options of the menu are not so useful because they cannot separate some elements. Anyone have an idea of a method to arrange the elements and the connectors in a better visualization? I have seen some discussions here in the forum, but none of them were useful to me /: Is it better to arrange during the generation of the elements, generation of the connectors, or is there a function that organizes everything and i could put in the end of the script?
-
You can automatically format the diagram using Project Interface.LayoutDiagramEx
Here's a snippet of the code I use
function layoutAutoDiagram(diagramID)
dim diagram
set diagram = Repository.getDiagramByID(DiagramID)
'if the diagram is an auto diagram then we do an automatic layout
if Left(diagram.name,LEN("AUTO_")) = "AUTO_" then
'auto layout diagram
dim diagramGUIDXml
'The project interface needs GUID's in XML format, so we need to convert first.
diagramGUIDXml = Repository.GetProjectInterface().GUIDtoXML(diagram.DiagramGUID)
'Then call the layout operation
Repository.GetProjectInterface().LayoutDiagramEx diagramGUIDXml, lsDiagramDefault, 4, 20 , 20, false
end if
end function
Geert
-
You can do what Geert suggests. It is possible to do a layout programmatically with a script. But be asured that this is the best way to get bald from pulling your hair. Sometimes you could start with the auto-layout from EA and lay hand on certain things. But even that is not simple and rarely fun...
q.
-
Ok, thanks guys. I will try to script, but when i start to lose my hair, i quit hahaha
-
Sorry Geert,i did not understand what is an Auto_diagram? Is it possible to set a diagram as "Auto_"? If yes, how do i do it? Is in the moment i create the diagram using my script?
-
Sorry Geert,i did not understand what is an Auto_diagram? Is it possible to set a diagram as "Auto_"? If yes, how do i do it? Is in the moment i create the diagram using my script?
There is no such thing as an Auto_diagram. This is part one of my EA-Matic scripts that automatically maintains certain diagrams. In order to avoid messing with the wrong diagrams, I check if the name of the diagram starts with "AUTO_"
Geert
-
Ah ok, it is just a name to assure you are in the right diagram... I could use the code and the elements are disposed in a better organisation. I will try now to handle the connector, maybe setting them to follow the autoroute layout.
-
Hello guys,
the last line does not work(i can storage the GUID in XML), because i can generated my diagram, but it changes nothing each time - there is no error in the debugger. Is this a Syntax error? Or my Version of EA does not handle the method?
dim diagramGUIDXml
diagramGUIDXml = Repository.GetProjectInterface().GUIDtoXML(diagram.DiagramGUID) 'get GUID in XML
Repository.GetProjectInterface().LayoutDiagramEx diagramGUIDXml, lsDiagramDefault, 50, 50 , 50, true
-
Try with a simple script to layout an existing diagram to make sure it works.
Then see how to use it with your diagram.
You might need to reload the diagram before the changes are visible.
If it still doesn't work, post the full code of your simple script that demonstrates the problem here and we can have a look.
Geert
-
Hi Geert, thanks for your answer. I will try what you propose.