Book a Demo

Author Topic: How to get the correct size for a shape script shape  (Read 4851 times)

GrahamL

  • EA User
  • **
  • Posts: 111
  • Karma: +2/-0
    • View Profile
How to get the correct size for a shape script shape
« on: June 22, 2020, 05:25:55 pm »
Hi
For my custom element I need an ellipse within a rectangle. This is relatively easy but when dragged onto a diagram the size of the element is wrong - there is an additional section at the bottom that means connectors drawn to the bottom of the shape appear disconnected.
Shape script is shown below, can anyone advise on a fix
Thanks
shape main
{
   noShadow=true;
   DefSize(100,70);
   setfillcolor(255,255,255); // default is white
   // Draw a transparent rectangle to contain the shape

   StartPath();

   Rectangle(0,0,100,70);

   EndPath();
FillAndStrokePath();
   if (HasTag('GSN Status','Completed'))
   {
      setfillcolor(0,176,80);
   }
   if (HasTag('GSN Status','Work In Progress'))
   {
      setfillcolor(255,192,0);
   }
   if (HasTag('GSN Status','Behind Schedule'))
   {
      setfillcolor(255,0,0);
   }
   if (HasTag('GSN Status','Not Required Now'))
   {
      setfillcolor(0,176,240);
   }

    Ellipse(5,5,95,65);
}

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: How to get the correct size for a shape script shape
« Reply #1 on: June 22, 2020, 05:54:03 pm »
Graham,

The statement

Code: [Select]
Rectangle(0,0,100,70);
Means: give me a rectangle from the top of my shape to 30 % of the height of my shape.
So it leaves the bottom 30% empty.
None of the other statements fill in that bottom 30% either.

If you want a rectangle that fills the whole shape, then do

Code: [Select]
Rectangle(0,0,100,100);
You should think of all the parameters in shapescripts as percentages of the whole shape, not pixels.

Geert

PS. Same answer as here: https://www.sparxsystems.com/forums/smf/index.php/topic,44587.msg262835.html#msg262835
« Last Edit: June 22, 2020, 05:56:02 pm by Geert Bellekens »

GrahamL

  • EA User
  • **
  • Posts: 111
  • Karma: +2/-0
    • View Profile
Re: How to get the correct size for a shape script shape
« Reply #2 on: June 22, 2020, 06:08:32 pm »
Hi Geert
Thanks for the hint, but does this mean that all shapes have to be 100x100
What if I need my shape 100x70
Im finding this quite confusing!

THanks

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: How to get the correct size for a shape script shape
« Reply #3 on: June 22, 2020, 06:33:48 pm »
Every shape is 100% height on 100% width

If you want your shape to be 100x70 you can set that in the default size
Code: [Select]
DefSize(100,70);
If you want your shape to have a fixed ratio of 100x70 then you can add

Code: [Select]
fixedAspectRatio=true;
Geert

GrahamL

  • EA User
  • **
  • Posts: 111
  • Karma: +2/-0
    • View Profile
Re: How to get the correct size for a shape script shape
« Reply #4 on: June 22, 2020, 06:50:49 pm »
Hi
This simple shape script still shows additional space at the bottom of the shape and I do not understand why?

shape main
{
   noShadow=true;
   fixedAspectRatio=true;

   DefSize(100,70);

    Ellipse(0,0,100,70);
 
}

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: How to get the correct size for a shape script shape
« Reply #5 on: June 22, 2020, 07:00:17 pm »
Graham,

It's the exact same thing as with the rectangle. You are only asking to fill 70% of the shape with an ellipse, so the bottom 30% is empty
You should consider the parameters to Ellipse (and Rectangle, and others) to be percentages of the whole shape.

So you are asking:
Draw an Ellipse with dimensions
- from 0% of the width to 100% of the width
- from 0% of the height to 70% of the height.

and since you set default height to 70 pixels, the height of you Ellipse will be 70% of 70 pixels = 49 pixels


Geert


Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: How to get the correct size for a shape script shape
« Reply #6 on: June 22, 2020, 07:07:20 pm »
Hi Graham,


Co-ordinates in shape script calls are relative to a 100x100 canvas. The actual size and proportions of that canvas can be controlled by the script or by the user, but the drawing methods always work on this 100x100 grid.

So in your case, DefSize(100,70); sets the actual (or external) size of the canvas.
Ellipse(0,0,100,70); then draws a squashed ellipse relative to the (internal) 100x100 canvas grid.

If you change it to Ellipse(0,0,100,100); you'll get a squashed ellipse filling the entire shape, since you've set the shape's size to 100x70. If you hadn't set that size, the same Ellipse() call would have produced a circle.

HTH,


/Uffe
My theories are always correct, just apply them to the right reality.

GrahamL

  • EA User
  • **
  • Posts: 111
  • Karma: +2/-0
    • View Profile
Re: How to get the correct size for a shape script shape
« Reply #7 on: June 22, 2020, 07:48:56 pm »
Got it!!
Must be monday :'(