Author Topic: Unable to move labels (by script) for ports on diagrams created by script  (Read 6870 times)

kjourdan

  • EA User
  • **
  • Posts: 71
  • Karma: +0/-0
    • View Profile
I have scripts that I use to position component ports and corresponding labels on diagrams; one script places the labels inside the component boundary next to the port and one script places the labels outside the component boundary next to the port.

On diagrams that I create manually (drag component onto diagram, enable ports of interest, etc), these scripts properly move the ports and their labels as expected. I can move these ports and labels around, run the scripts and the ports and labels are moved back to their position. Nothing unusual here.

I created a script that creates a diagram, adds components and their ports to the diagram.  Running my port/label placement scripts results in the ports being moved to their expected positions on the component boundaries.  The labels however appear to at their default position (outside the component, slightly below the port and extending away from the component).  If I move the port manually, the label remains that the same positional offset from the port.  I can manually move the label on the diagram.  When I run my scripts, the port is moved back into position but the label does not move where I expect; the label remains at the same positional offset from the port after I had manually moved them.

If I hide the ports for a given component on that diagram (select component, right-click, Structural Elements, None) and then show the ports (select component, right-click, Structural Elements, All), the ports and labels go to the positions that would occur if I manually dragged the component onto the diagram.  When I run my scripts, these ports and labels get moved into proper position; the labels for ports on other components continue to remain in their default positions.

Is there an attribute for these diagram objects that needs to be set to allow the labels to be moved?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
I'd guess that ObjectStyle is not set when you create diagramObjects programmatically. Just verify that with the SQL scratchpad and eventually create something like
Code: [Select]
LBL=CX=25:CY=13:OX=0:OY=0:HDN=0:BLD=0:ITA=0:UND=0:CLR=-1:ALN=1:ALT=0:ROT=0;
q.

kjourdan

  • EA User
  • **
  • Posts: 71
  • Karma: +0/-0
    • View Profile
The problem is related to the Style attribute after creating the diagram object.  After creation of the diagram object, the Style is set to its default of "".  My port placement scripts were retrieving the Style attribute and setting the OX, OY and ROT to fixed values.  The CX and CY values were intended to be unaltered.  My logic for parsing the Style to extract CX and CY and did not take into account that Style may not be populated; Style is always populated when elements are manually added to the diagram. Since no CX or CY values exist in the Style, the parsing would result in NaN (not a number). The value written to Style would then have CX and CY as NaN.

kjourdan

  • EA User
  • **
  • Posts: 71
  • Karma: +0/-0
    • View Profile
It is indeed related to the Style. What is peculiar is that if you set the Style to a bad string (eg. CX=NaN: CY=NaN) then manually move the label, the Style is not corrected but the label is where it placed.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
It is indeed related to the Style. What is peculiar is that if you set the Style to a bad string (eg. CX=NaN: CY=NaN) then manually move the label, the Style is not corrected but the label is where it placed.
Don't make any assumptions on wrong/bad premises.

q.

Helmut Ortmann

  • EA User
  • **
  • Posts: 970
  • Karma: +42/-1
    • View Profile
Hello,

In the open source project hoTools (see https://github.com/Helmut-Ortmann/EnterpriseArchitect_hoTools/wiki/Port) I have implemented moving Ports and more. As far as I can remember setting Style works. As usual, it takes some time and a bit of tinkering to grasp how to do it correctly.

Maybe have a look at the code and see how it might work.

The books  Scripting Enterprise Architect and Inside Enterprise Architect of qwerty may help you. The good think about these helpers is that he keeps the books up to date.  If you have found something new, send it to qwerty and he'll incorporate it.


Kind regards,

Helmut

Coaching, Training, Workshop (Addins: hoTools, Search&Replace, LineStyle)

kjourdan

  • EA User
  • **
  • Posts: 71
  • Karma: +0/-0
    • View Profile
Thanks all for the help.  Curious if anyone knows how the CX and CY values are calculated. Is there a formula for CX assuming CY is 13?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
I guess it's relative from the center position of the port.

q.