Author Topic: Shape Script - multiple labels and label 'text' alignment  (Read 612 times)

OpenIT Solutions

  • EA User
  • **
  • Posts: 475
  • Karma: +5/-0
    • View Profile
Shape Script - multiple labels and label 'text' alignment
« on: September 06, 2018, 07:49:43 pm »
Hi,

Does anyone have an example of how we can have multiple labels in a Shape Script. Specifically, I want to have a label shown below an Activity and another above, the code below will add below. But if I add a second label (as shown below) - both labels just appear above...

shape label
{
   layouttype = "leftright";
        v_align = "top";
   h_align = "left";
   setOrigin ("SW",0,0);
   
   if (HasTag("id"))
   {
      println ("#TAG:id#");
   }
}

this works fine, however if I then add,

shape label
{
   layouttype = "leftright";
        v_align = "top";
   h_align = "left";
   setOrigin ("NW",0,0);
   
   if (HasTag("frequency"))
   {
      println ("#TAG:frequency#");
   }
}

both labels get displayed at the NW (top left) ... not what I want. I also have another problem that I'm hoping someone can help with, although the label placement is horizontally aligned to the left - the actual label text is not - its centred - is there a way to set the alignment if the actual text in a shape script - not just its placement ?
   

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 8601
  • Karma: +210/-26
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Shape Script - multiple labels and label 'text' alignment
« Reply #1 on: September 06, 2018, 09:42:21 pm »
Seems wrong to have two shapes with the name label, have you tried using other names?

You can also print something in your shape on a location you choose. Have you considered that?

Geert

Sunshine

  • EA User
  • **
  • Posts: 715
  • Karma: +51/-3
  • Let's just do it
    • View Profile
Re: Shape Script - multiple labels and label 'text' alignment
« Reply #2 on: September 07, 2018, 06:34:34 am »
Perhaps if you could share the full shape script we might be able to help.
Also if you could share what version of Sparx EA you are using that may help too.
If you right click on the text you get a context menu for text alignment and you can make it left, center or right justified.
Happy to help
:)

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 6303
  • Karma: +108/-91
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Shape Script - multiple labels and label 'text' alignment
« Reply #3 on: September 07, 2018, 09:34:29 am »
Seems wrong to have two shapes with the name label, have you tried using other names?

You can also print something in your shape on a location you choose. Have you considered that?

Geert
+1  That's what we do.  But be warned, it has to be within the shape (the define) to be copied correctly onto other documents (like emails).

Paolo
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

OpenIT Solutions

  • EA User
  • **
  • Posts: 475
  • Karma: +5/-0
    • View Profile
Re: Shape Script - multiple labels and label 'text' alignment
« Reply #4 on: September 11, 2018, 12:37:50 am »
Geert, 'shape label' is a reserved section in a shape script. Looks like you can't have multiple shape label sections however and that you can only set the origin once per 'shape label' section. So I guess the only way to meet my requirement here is to add two subshape sections to my script, which I wanted to avoid - but hey.

Steffen Lehr

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: Shape Script - multiple labels and label 'text' alignment
« Reply #5 on: October 24, 2018, 03:14:20 am »
According to https://www.sparxsystems.com.au/enterprise_architect_user_guide/14.0/modeling_tools/writing_scripts.html
at least for connectors there should be the possibility to place the labels by defining "label <positionLabel>{...}" with <positionLabel> = "MiddleTopLabel" or "MiddleBottomLabel".

When used, the labels are initially drawn at the expected positions, but as soon as as the newly created connector is deselected, the MTL and MBL overlap at the MBL position. Is there a way to understand that behavior or a known workaround?