Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: kebrahim on February 15, 2020, 04:22:28 am
-
I hope somebody can help. I am adding ports to an element in EA via automation interface and the position of the port is calculated from element's coordinates and size
I use all Update and Refrech methods and everything looks fine. But when I add my element (with its embedded ports) to a new diagram all port position information
is lost.
I use following methods to add ports to elements and to a diagram
1. Port position in diagram is calculated based on parant element position and site
string position = "l=" + left + ";r=" + right + ";t=" + top + ";b=" + bottom + ";"; // position of the port is calculated based on element position and size
2. Add new object to a diagram
var diagOb_port1 =(EA.DiagramObject) hwinputview.DiagramObjects.AddNew(position, "") ;
3. set style and objectID
diagOb_port1.Style = "LBL=CX=43:CY=15:OX=-85:OY=0:HDN=0:BLD=0:ITA=0:UND=0:CLR=-1:ALN=0:ALT=0:ROT=0;";
diagOb_port1.ElementID = SignalBlockPort1.ElementID;
I use refresh, update methods on elements and diagram objects . Sofar everything looks fine.
As I mentioned before, when adding the element to a new diagram port position information ist lost
Can anybody please help? I am using EA 15 and VS2019
thanks in advance
Keyvan
-
Element positions are diagram specific. On each diagram it can have a different position.
If you add an element to a new diagram there here is no position information.
If you want the same positioning as on another diagram you'll have to copy it from the other diagram.
Geert
-
thanks Geert for your promt reply.
Any hints how I can do this (copying etc)?
thanks
-
Right out of my head: the ports are 15x15 pixels in size. From the border position of the parent element you need to go in/out 7 pixels depending as to where you are. That determins the "correct" port positions. Some EA versions have messed that up with automation and you end up with random positions (you could alternatively go directly to the database in these cases and make the position columns for t_diagramobject what they were supposed to by). Tricky though as to which order you have to save, load and reload things (there was a very recent thread about that, but finding anything in this board - well...).
Further there are (in more recent EA versions) resizable ports. I haven'd toyed with those from the automation. So there might be dragons.
q.
-
thanks Geert for your promt reply.
Any hints how I can do this (copying etc)?
thanks
OK. got it.
That means I need a Addin, which implements
bool EA_OnPreNewDiagramObject(
Repository Repository,
EventProperties Info)
and therein search and find my Element in a Diagram and copy port position information AND add the object to the current diagram. correct?
I had a look at your nice tutorial Tutorial: Create your first C# Enterprise Architect add-in in 10 minutes
What I wasn't able to do was the registry part. The registry structure on win 10 looks different
I have added as follows
Computer\HKEY_CURRENT_USER\Software\Sparx Systems\EA400\EA\EAAddins\MyAddin
(Standard) REG_SZ MyAddin.EAAddin
I have added EAAddins as it didn't exist before
best
Keyvan