Author Topic: Organize diagrams and connectors using VBscript  (Read 2350 times)

Andre_b_b

  • EA User
  • **
  • Posts: 40
  • Karma: +0/-1
    • View Profile
Organize diagrams and connectors using VBscript
« 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?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13303
  • Karma: +557/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Organize diagrams and connectors using VBscript
« Reply #1 on: July 04, 2023, 12:34:43 am »
You can automatically format the diagram using Project Interface.LayoutDiagramEx

Here's a snippet of the code I use

Code: [Select]
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

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Organize diagrams and connectors using VBscript
« Reply #2 on: July 04, 2023, 03:42:12 am »
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.

Andre_b_b

  • EA User
  • **
  • Posts: 40
  • Karma: +0/-1
    • View Profile
Re: Organize diagrams and connectors using VBscript
« Reply #3 on: July 04, 2023, 06:10:01 pm »
Ok, thanks guys. I will try to script, but when i start to lose my hair, i quit hahaha

Andre_b_b

  • EA User
  • **
  • Posts: 40
  • Karma: +0/-1
    • View Profile
Re: Organize diagrams and connectors using VBscript
« Reply #4 on: July 04, 2023, 09:51:45 pm »
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?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13303
  • Karma: +557/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Organize diagrams and connectors using VBscript
« Reply #5 on: July 04, 2023, 10:12:26 pm »
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

Andre_b_b

  • EA User
  • **
  • Posts: 40
  • Karma: +0/-1
    • View Profile
Re: Organize diagrams and connectors using VBscript
« Reply #6 on: July 04, 2023, 10:45:53 pm »
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.

Andre_b_b

  • EA User
  • **
  • Posts: 40
  • Karma: +0/-1
    • View Profile
Re: Organize diagrams and connectors using VBscript
« Reply #7 on: July 06, 2023, 07:47:10 pm »
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

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13303
  • Karma: +557/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Organize diagrams and connectors using VBscript
« Reply #8 on: July 06, 2023, 08:14:06 pm »
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

Andre_b_b

  • EA User
  • **
  • Posts: 40
  • Karma: +0/-1
    • View Profile
Re: Organize diagrams and connectors using VBscript
« Reply #9 on: July 06, 2023, 09:48:53 pm »
Hi Geert, thanks for your answer. I will try what you propose.