Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: survex on May 25, 2015, 04:56:16 am
-
How to apply any layout (say spring) to diagram via scripting?
-
ProjectInterface.LayoutDiagramEx
q.
-
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?
-
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.
-
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();