Author Topic: how is port position saved and used in EA?  (Read 577 times)

kebrahim

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
how is port position saved and used in EA?
« 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












Geert Bellekens

  • EA Guru
  • *****
  • Posts: 9733
  • Karma: +286/-30
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: how is port position saved and used in EA?
« Reply #1 on: February 15, 2020, 04:47:23 am »
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

kebrahim

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: how is port position saved and used in EA?
« Reply #2 on: February 15, 2020, 04:55:03 am »
thanks Geert for your promt reply.
Any hints how I can do this (copying etc)?

thanks

qwerty

  • EA Guru
  • *****
  • Posts: 10811
  • Karma: +244/-220
  • I'm no guru at all
    • View Profile
Re: how is port position saved and used in EA?
« Reply #3 on: February 15, 2020, 08:17:20 am »
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.

kebrahim

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: how is port position saved and used in EA?
« Reply #4 on: February 15, 2020, 07:39:18 pm »
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