2022-04-11 09:30 AM
Hello,
I'm trying to set multiple IF statements depending on a values list set on the Paramaters. If I set only to statements everything works as expected, but when I add more than two statements I get an error.
Here is the code:
!!!!!======== MODULE WIDTH ===========
IF WIDTH="600" THEN MOD_WIDTH=0.6
IF WIDTH="900" THEN
MOD_WIDTH=0.9
ENDIF
!!!!!======== MODULE DEPTH ===========
IF DEPTH="300" THEN MOD_DEPTH=0.3
IF DEPTH="400" THEN
MOD_DEPTH=0.4
IF DEPTH="500" THEN
MOD_DEPTH=0.5
IF DEPTH="600" THEN
MOD_DEPTH=0.6
ENDIF
RECT2 0,0, MOD_WIDTH, MOD_DEPTH
Juan.
Solved! Go to Solution.
2022-04-11 10:18 AM
If your IF/THEN is all on one line, you don't need an ENDIF.
If you split it over multiple lines then you do need an ENDIF for every IF/THEN.
IF WIDTH="600" THEN MOD_WIDTH=0.6
IF WIDTH="900" THEN
MOD_WIDTH=0.9
ENDIF
!!!!!======== MODULE DEPTH ===========
IF DEPTH="300" THEN MOD_DEPTH=0.3 !!!don't need ENDIF if single line
IF DEPTH="400" THEN
MOD_DEPTH=0.4
ENDIF
IF DEPTH="500" THEN
MOD_DEPTH=0.5
ENDIF
IF DEPTH="600" THEN
MOD_DEPTH=0.6
ENDIF
RECT2 0,0, MOD_WIDTH, MOD_DEPTH
But for the sake of clean coding I would do them all the same way.
I prefer to split them over multiple lines.
Barry.
2022-04-11 10:18 AM
If your IF/THEN is all on one line, you don't need an ENDIF.
If you split it over multiple lines then you do need an ENDIF for every IF/THEN.
IF WIDTH="600" THEN MOD_WIDTH=0.6
IF WIDTH="900" THEN
MOD_WIDTH=0.9
ENDIF
!!!!!======== MODULE DEPTH ===========
IF DEPTH="300" THEN MOD_DEPTH=0.3 !!!don't need ENDIF if single line
IF DEPTH="400" THEN
MOD_DEPTH=0.4
ENDIF
IF DEPTH="500" THEN
MOD_DEPTH=0.5
ENDIF
IF DEPTH="600" THEN
MOD_DEPTH=0.6
ENDIF
RECT2 0,0, MOD_WIDTH, MOD_DEPTH
But for the sake of clean coding I would do them all the same way.
I prefer to split them over multiple lines.
Barry.
2022-04-11 10:18 AM
You did not close the second and third last IF statement with ENDIF
2022-04-11 10:37 AM
Unrelated to the question, BUT if your input is set to "Length Type" it is automatically converted to meters in the scripts. So an input value of 300 (mm) is read as 0.3 in the script. Your parameter script would then be
VALUES "Depth" 0.3, 0.4, 0.5, 0.6, 0.9
In doing this, there would be no need to have all of these statements to convert your "Text Type" into a "Length Type". Unless I guess if you are wanting to include text within the input for what ever reason, or the usage is completely different to what I am thinking.
Ling.
AC22-28 AUS 3001 | 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 |
2022-04-11 10:41 AM
Thank you for pointing it out, just noticed and fixed it in VALUES.
2022-04-11 10:42 AM
Nood question of the day, there is no performance difference between one line IF or split it in multiple lines?
2022-04-11 10:42 AM
Thank you, that was my problem/doubt.
2022-04-11 10:47 AM
No.
I just think it is clearer on multiple lines.
Then you can indent between the IF/ENDIF to make it clear that it is a little group.
Seeing as we have no colour coding of scripts in GDL.
Barry.
2022-04-11 11:11 AM
I would also avoid scripting in ALL CAPS and keep capitalisation to key things such as commands for additional clarity.
AC22-28 AUS 3001 | 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 |
2022-04-13 12:33 PM - edited 2022-04-13 12:38 PM
Generally users aren't affected by GDL code performance. Executing the script is much faster than showing its result model/drawing.
SEO operations (groups, cuts), large file I/O can start to be problematic.