Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: phamrt1 on October 17, 2008, 03:24:33 am

Title: Create diagram objects with variable positions
Post by: phamrt1 on October 17, 2008, 03:24:33 am
I was able to create objects in a diagram using code like this:

DiagOb = (EA.DiagramObject)New_Diagram.DiagramObjects.AddNew("l=200;r=300;t=100;b=150;", "");

How do I replace the hard coded numbers (200,300,100,150) with variables so I can go through a loop and add multiple objects and place them in different positions in the diagram.  When I tried to assign values to the variables and use them in this code, the variables don't get used:

DiagOb = (EA.DiagramObject)New_Diagram.DiagramObjects.AddNew("l=Left;r=Right;t=Top;b=Bottom;", "");

I have multiple swimlanes created in the diagram.  Can I make the objects part of the swimlanes such that they can be positioned within the swimlanes?  For ex,  object 1 placed in Swimlane 1, object 2 placed in Swimlane 2...

Thanks

Title: Re: Create diagram objects with variable positions
Post by: Chris Tatem on October 17, 2008, 05:04:37 am
Something like this *should* work.

String newStuff;
int Top = 100;
int Bottom = 150;
int Left = 10;
int Right = 110;
int shiftRight = 100;

[loop]
Left += shiftRight ;
Right += shiftRight;

newStuff = "l=" + Left + ";r=" + Right + ";t=" + Top + ";b=" + Bottom + ";";

DiagOb = (EA.DiagramObject)New_Diagram.DiagramObjects.AddNew(newStuff, "");

[endLoop]

I think this will move the objects left to right across your screen, in increments of 100.
or however you want to create the String outside the AddNew call.
Title: Re: Create diagram objects with variable positions
Post by: phamrt1 on October 17, 2008, 06:57:45 am
It worked  :).  Thanks a bunch!