2023-10-12 02:59 AM - last edited on 2024-09-26 01:48 PM by Doreena Deng
Hi everyone
I am using the following code to determine the size of the page so I can show the page size along with the scale in our drawing title
sheetSize = "A1"
if AC_LayoutRect[3] < 841 then
sheetSize = "A1"
endif
if AC_LayoutRect[3] < 594 then
sheetSize = "A2"
endif
if AC_LayoutRect[3] < 420 then
sheetSize = "A3"
endif
For some reason if the sheet size is A2 and AC_LayoutRect[3] = 562.5 the sheet size will still drop though all the if statements to the last if statement and set it to A3
Is there a specific way to read the value out of the array so that it can be used as a comparison be?
I cannot figure out why the last statement is reading true
Any help would be greatly appreicated
Cheers
Eric
Solved! Go to Solution.
2023-10-16 09:41 PM - edited 2023-10-16 09:46 PM
Hello @Eric B ,
The issue is simple, it's a unit problem. Your code checks values in meters and you thought it was checking them in millimeters.
In the GDL script, I always keep in mind that length values are in meters. I don't know if this can be changed somewhere but that's my rule when it comes to those. The reason the last condition is true, it's because an A2 sheet size is indeed inferior to 420 meters 😅
Have your constants in meters and this should work. Also, I would have nested ifs preferably, it looks cleaner and prevent unnecessary tests.
sheetSize = ""
if AC_LayoutRect[3] < 0.420 then
sheetSize = "A3"
else
if AC_LayoutRect[3] < 0.594 then
sheetSize = "A2"
else
sheetSize = "A1" ! default
endif
endif
2023-10-12 03:08 AM
Can you not just:
TEXT2 0, 0, AC_LayoutRect[3]
or does that not work for some weird odd reason?
AC22-23 AUS 7000 | Help Those Help You - Add a Signature |
Self-taught, bend it till it breaks | Creating a Thread |
Win11 | i9 10850K | 64GB | RX6600 | Win10 | R5 2600 | 16GB | GTX1660 |
2023-10-12 04:21 AM
That will output the right hand bottom corner of the sheet
I am trying to use that to create a crude switch statement so it will output A1, A2 or A3 as the sheet size
2023-10-12 06:18 AM
I mean so that you can see what it is returning since you said your output is coming up as A3 even though your sheet size is greater than 420. Print out the variables in question to check that they are returning the expected values.
I have a list of 47 different calculated variables in one of my objects that I have printed out at one point or another. Lots and lots of trig...
AC22-23 AUS 7000 | Help Those Help You - Add a Signature |
Self-taught, bend it till it breaks | Creating a Thread |
Win11 | i9 10850K | 64GB | RX6600 | Win10 | R5 2600 | 16GB | GTX1660 |
2023-10-12 08:20 AM
Apologies - yes I've done that
An A2 returns 562.5 which is why I am stumped as to why it still enters the third if statement
2023-10-16 07:52 AM
I have looked into this further
If I just output the contents of AC_LayoutRect[3] of an A2 sheet of paper I get a value of 567.2
All the if statements will be evaluated but it will still enter the A3 if statement
If I change the coding and hard code the value 567.2 instead of AC_LayoutRect[3] then it goes as far as the A2 statement and will display the correct paper size
Is there something specific I should be doing to read this value or is there a specific place that this array is being populated and therefore I am trying to read it too soon? I am kind of at a loss as to why it won't run correctly
Cheers
Eric
2023-10-16 09:41 PM - edited 2023-10-16 09:46 PM
Hello @Eric B ,
The issue is simple, it's a unit problem. Your code checks values in meters and you thought it was checking them in millimeters.
In the GDL script, I always keep in mind that length values are in meters. I don't know if this can be changed somewhere but that's my rule when it comes to those. The reason the last condition is true, it's because an A2 sheet size is indeed inferior to 420 meters 😅
Have your constants in meters and this should work. Also, I would have nested ifs preferably, it looks cleaner and prevent unnecessary tests.
sheetSize = ""
if AC_LayoutRect[3] < 0.420 then
sheetSize = "A3"
else
if AC_LayoutRect[3] < 0.594 then
sheetSize = "A2"
else
sheetSize = "A1" ! default
endif
endif
2023-10-18 10:58 AM
You are 100% correct
I have a mul2 to convert all the code to mm but it was after the if statements and of course because the array was storing the dimensions in mm I didn't give it another thought
Thanks for you help with this as I had been looking at the code trying to figure out what I had done wrong
2023-10-30 12:39 PM
Hi,
Parameters are never affected by transformations. Length parameters are always stored as meters - work environment has an effect on how they are shown on the UI, and you can use imperial numbers in code, but the parameter actual values will still be meters. Angles are always degrees.
Another thing to know is that the data is two diagonal points of the printable area (blue border) relative to the drawing title's coordinate system, plus the rotation of the drawing title relative to the layout. The length of one side has to be calculated from these.