Author Topic: Apply layout to diagram via scripting  (Read 5413 times)

survex

  • EA User
  • **
  • Posts: 76
  • Karma: +1/-1
    • View Profile
Apply layout to diagram via scripting
« on: May 25, 2015, 04:56:16 am »
How to apply any layout (say spring) to diagram via scripting?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Apply layout to diagram via scripting
« Reply #1 on: May 25, 2015, 06:20:21 am »
ProjectInterface.LayoutDiagramEx

q.
« Last Edit: May 25, 2015, 06:21:01 am by qwerty »

survex

  • EA User
  • **
  • Posts: 76
  • Karma: +1/-1
    • View Profile
Re: Apply layout to diagram via scripting
« Reply #2 on: May 27, 2015, 06:41:00 am »
Here's a definition of the function:
LayoutDiagramEx (string DiagramGUID, long LayoutStyle, long Iterations, long LayerSpacing, long ColumnSpacing, boolean SaveToDiagram)

And description of LayoutStyle parameter:

LayoutStyle accepts the following options
•      Default Options:
    - lsDiagramDefault
    - lsProgramDefault
 
•      Cycle Removal Options:
    - lsCycleRemoveGreedy
    - lsCycleRemoveDFS
 
•      Layering Options:
    - lsLayeringLongestPathSink
    - lsLayeringLongestPathSource

lsLayeringOptimalLinkLength
 
•      Initialize Options:
    - IsInitializeNaive
    - IsInitializeDFSOut

IsInitializeDFSIn
 
•      Crossing Reduction Option:
    - lsCrossReduceAggressive

•      Layout Options - Direction

lsLayoutDirectionUp

lsLayoutDirectionDown

lsLayoutDirectionLeft

lsLayoutDirectionRight

And what should I pass as LayoutStyle parameter? What kind of long should it be?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Apply layout to diagram via scripting
« Reply #3 on: May 27, 2015, 06:47:17 am »
Ah, that help... Look into the constants that are defined in the ScriptingLib MDG. Or probably you number the list which appears after ConstLayoutStyles Enum in the help.

q.

survex

  • EA User
  • **
  • Posts: 76
  • Karma: +1/-1
    • View Profile
Re: Apply layout to diagram via scripting
« Reply #4 on: May 27, 2015, 06:06:15 pm »
Here's the working code snippet:

!INC Local Scripts.EAConstants-JScript

function main ()
{
      var DiagramGUID, LayoutStyle, Iterations, LayerSpacing, ColumnSpacing, SaveToDiagram;
      var Project as EA.Project;
      
      Project = Repository.GetProjectInterface();
      
      DiagramGUID = Project.GUIDtoXML( Repository.GetCurrentDiagram().DiagramGUID );
      
      //See ConstLayoutStyles in EAConstants-JScript
      //LayoutStyle = lsDiagramDefault
      LayoutStyle = lsCycleRemoveDFS | lsLayeringOptimalLinkLength | lsInitializeDFSOut | lsLayoutDirectionDown;
      
      Iterations = 4;
      LayerSpacing = 20;
      ColumnSpacing = 20;
      SaveToDiagram = false;

      Project.LayoutDiagramEx( DiagramGUID, LayoutStyle, Iterations, LayerSpacing, ColumnSpacing, SaveToDiagram );
}

main();