The Global Archicad Community

Stay informed. Get help. Share your knowledge.

Topics specific to the scripting and development of Library Parts and Libraries using Param-O or the Geometric Description Language – GDL. (Example: How do you use “REQUEST” GDL commands?)

Moderators: Karl Ottenstein, LaszloNagy, ejrolon, Barry Kelly, Gordana Radonic, nbalogh, mnguyen, gkmethy, rmasaki, Akos Somorjai, Csilla Mai, Peter Baksa

User avatar
By Barry Kelly
#321010
Is there any way to determine the scale in the master script?
Since version 20 it will always default to a value of 100.


The issue I have is I have created a label that reads text values from objects.
The text is stretchy and will adjust with the label text box width - so I can have multi-line text if needed.
All works really well.

The default width of the label is fine for lengthy text.
But when the text is very short, the text box default is really too wide and is a bit annoying.

text_box_width.jpg
text_box_width.jpg (24.13 KiB) Viewed 217 times

I can manually stretch the box but that is not the issue - I am trying to avoid that.
I can determine the length of the text and can set the text box width accordingly, but because it is a parameter (A), it must be set in the Parameter or Master scripts.

I need to label my objects at different scales - which it where the problem arises.

The text box width needs to change automatically based on the scale of the object.
At 1:100 the width might be 2000mm, at 1:50 it would only need to be 1000mm wide and at 1:200 it would need to be 4000mm wide.

But because I can not determine the scale in the master script, there is no way I can determine a multiplication factor to use for that scale.
I could add a manual option into the object for the user to choose the scale, but I really don't want to do that.

I have tested and proved that I can automatically set the text box width based on the maximum length of the text string.
I just need to be able to determine the scale now.


So how can I determine the current scale from the master script?


Barry.
#321015
short answer: you cannot.

The GLOB_SCALE global variable which returns the scale was deprecated in version 20 for the parameter and master script. However you can still use it in the 2D, 3D and interface scripts.

So the flaw in your logic is that you are trying to assign the text box size to a parameter.

The solution is to forget your "A" value for the text box size and simply do all the text box size determination in the 2D script, where you can still reference the scale with the GLOB_SCALE variable.
#321016
This is described (briefly) in the GDL Reference Guide STW expression where it says:
STW (string_expression)
Returns the (real) width of the string in millimeters displayed in the current style. The width in meters, at current scale, is STW(string_expression)/1000*GLOB_SCALE
#321055
Kristian Bursell wrote: Tue Jan 12, 2021 10:36 am So the flaw in your logic is that you are trying to assign the text box size to a parameter.

Thanks Kristian,
I understand how it works in 2D.
The problem is exactly that I want to control the width parameter for the text box.
My labels will only ever be placed at one scale, I have separate annotation layers for each scale so the text can appear in different locations or even say completely different things.

I can stretch the box and of course the width parameter will adjust to suit.
I want it to get the width of the text string and adjust the text box width parameter automatically to reduce it if the box is wider than the actual text.
It can be done - I just can't set the parameter automatically.

I can stretch the box, or I can set up a favourite with a reduced width or I could possibly even add a manual option where the user set the scale.
But I would rather it all be automatic.

I can do it all without using the text box width parameter, but using the label it is a bit difficult to explain to users that with all other labels, you can adjust the width in the info box, but with this label they can not.
Maybe that is just what I will have to do - it is stretchy after all so easy to adjust.


Barry.
#321066
I understand how it works in 2D.
I thought so.
I even commented to my wife when I saw this post last night, that a very experienced and knowledgeable Archicad and GDL user has asked a question I would expect from a novice.
#321067
I remember setting up a label where the width parameter was actually a multiplication of the the resulting 2D. So It was still automated based on the scale and the STW but adjustable based on my width multiplying parameter.

however I no longer use this part as i think it was a clumsy result. It required two width parameters, one that was for the use of the dynamic hotspot which would alter the value of the width multiplication, otherwise the multiplication would jump to 2x after moving 2 meters. Very messy logic, but may work if you get the math between the STW, dynamic hotspot parameter, & width multiplying parameter correct... maybe.
#321070
Kristian Bursell wrote: Wed Jan 13, 2021 2:49 am
I understand how it works in 2D.
I thought so.
I even commented to my wife when I saw this post last night, that a very experienced and knowledgeable Archicad and GDL user has asked a question I would expect from a novice.
This is partly just a fishing exercise to see if anyone has any clever solutions (I'm not expecting they will).
And partly to bring it to the attention of Graphisoft - I know this is not an official channel to them but they do read here.
I lost track of the number of times I had discussions with GS when they made the change in 19/20 that the Globals won't work in the parameter script any more.
I am a member of their development forum.

Start rant.
Yes I know that I can have the same instance of an object (label) displaying at different scales and that is why GLOB_SCALE can not be used as it will constantly have conflicting information as the scale is changed.
It also had something to do with teamwork if I remember correctly from the discussions, as different members can be looking at the same object with different settings/views/scale at the same time and sending the results will create conflict.
But what frustrates me is that it used to work just fine in 18 and below when it was allowed.
And I don't use teamwork.
So just let the user be aware there could be a problem and let them decide if they want to take the risk.

My rant is over.
Barry.
#321071
Fair rant; it is unfortunate not having access to global variables in parameter/master scripts.
Maybe they could make them conditional, or we GDL coders could add in conditions so they don't cause issues in teamwork projects.
#321312
Hi Barry,

based on your specification specification:
  • My labels will only ever be placed at one scale, I have separate annotation layers for each scale so the text can appear in different locations or even say completely different things.
  • I need to label my objects at different scales - which it where the problem arises. The text box width needs to change automatically based on the scale of the object.
I think if you don't change the scale, you can work with an absolute width. Set the parameter default to 0, and draw an editable hotspot at the calculated text width if the parameter is zero, at the parameter otherwise. As long as the user doesn't touch the hotspot, the width will be automatic, and fixed-width after.
#321513
For now I have added a manual scale parameter that the user can choose.
Just set it to suit the scale the label is being used in.

Barry.