Book a Demo

Author Topic: Shape script to override just one attribute leads to "invisible" shape?  (Read 2482 times)

EAabecedarian

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Here's from the User Guide what confuses me:
Quote
Shape Scripts operate on the basis that the default (UML) representation is used unless the script contains an alternative definition.
[...]
If you have an empty shape routine, it overrides the default; so, a blank 'shape label' prevents the creation of the normal floating text label for elements that have them

For my MDG, I'd like to override only the border color of a stereotyped "Component" based on some tagged value:

shape main{
   v_align="center";
   h_align="center";
   
   // Check the tagged value "TV1" and set border colour accordingly   
   if (hastag("TV1", "Red Type"))
   {
      setpencolor(255, 0, 0);
   }
   
   if (hastag("TV1", "Green Type"))
   {
      setpencolor(0, 255, 0);
   }

   if (hastag("TV1", "Blue Type"))
   {
      setpencolor(0, 0, 255);
   }
}

With this, any element of that stereotype I add to a diagram is there, but "invisible", so I see no border, no filling, no text, etc.
Is this because my existing "shape main" is actually interpreted as "empty" and thus overriding EVERYTHING, so only the pen color applies (which, of course, has no effect without any drawing specified)?
Do I really have to add the other definitions manually, or is there a way to keep the shape's default?

BR,

EAabecedarian

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Shape script to override just one attribute leads to "invisible" shape?
« Reply #1 on: February 08, 2022, 06:51:41 pm »
In a shapescript there are a few shapes you can define.

One of them is the main shape, the others are labels and decorations.
You choose to provide an alternative definition for the main shape, so the standard main shape is not used.
You can call the base main shape using DrawNativeShape() or DrawParentShape()

so something like this might work:

Code: [Select]
shape main{
 
   // Check the tagged value "TV1" and set border colour accordingly   
   if (hastag("TV1", "Red Type"))
   {
      setpencolor(255, 0, 0);
   }
   
   if (hastag("TV1", "Green Type"))
   {
      setpencolor(0, 255, 0);
   }

   if (hastag("TV1", "Blue Type"))
   {
      setpencolor(0, 0, 255);
   }
   DrawNativeShape();
}
Unless ofcourse the native shape defines the pencolor itself (usually not), in that case you are out of luck.

Geert

EAabecedarian

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: Shape script to override just one attribute leads to "invisible" shape?
« Reply #2 on: February 08, 2022, 07:17:39 pm »
Thx Geert! It works  :)
And after searching for "drawnativeshape" I found this section: https://sparxsystems.com/enterprise_architect_user_guide/15.2/modeling/add_custom_compartments_to_ele.html
Script example 2 goes in the same direction.

BR,

EAabecedarian