BIM Coordinator Program (INT) April 22, 2024
Find the next step in your career as a Graphisoft Certified BIM Coordinator!
GDL
About building parametric objects with GDL.
SOLVED!

UNDEFINED Array Values Question

GDL Enthusiast
Enthusiast

Hi,

 

I have a problem that is baffling me. I have simplified it down to how to deal with an Undefined line item in an array. Here is the script:

 

Parameter Script:

values{2} "bolt",             1, `Simple`,
                              2, `Complex`
values{2} "nut",              1, `Simple`,
                              2, ` Complex `

 

The 2D Script has a variety of bolt and nut types using IF statements with text notes for bolt or nut type. For each a different text result is given, i.e.

 

2D Script

IF Bolt = 1   THEN   TextA1 = "IN1 String to test the text."
IF Bolt = 2   THEN   TextA2 = "IN2 String to test the text."
IF Nut = 1    THEN   TextA3 = "IN3 String to test the text."
IF Nut = 2    THEN   TextA4 = "IN4 String to test the text."

 

If the user selects Bolt = 1 then TextA1 is defined, but TextA2 is undefined causing an error in the following array:

DIM ItemText[4]
ItemText[1] = TextA1
ItemText[2] = TextA2
ItemText[3] = TextA3
ItemText[4] = TextA4

! Show Result
Text2 0,0,ItemText[1]
Text2 0,0.05,ItemText[2]
Text2 0,0.1,ItemText[3]
Text2 0,0.15,ItemText[4] 


I have tried this alternative code to handle the array using IF statements but I can't think of a way to write IF TextA1 = undefined THEN:

 

DIM ItemText[3]
IF TextA1 = "" THEN ItemText[1] = "" ELSE ItemText[1] = TextA1
IF TextA2 = "" THEN ItemText[2] = "" ELSE ItemText[2] = TextA2
IF TextA3 = "" THEN ItemText[3] = "" ELSE ItemText[3] = TextA3

...etc

 

Is there a way to make the array ignore undefined values? 

Many thanks, Matt

1 ACCEPTED SOLUTION

Accepted Solutions
Solution
Jochen Suehlo
Advisor
ItemText[2] is undefined because TEXTA2 is undefined in the default settings.
The best way is to initialize all String Values before they are used.
If you do this at the top of the script, you will have no errors.
 
TextA1 = ""
TextA2 = ""
TextA3 = ""
TextA4 = ""

IF Bolt = 1   THEN   TextA1 = "IN1 String to test the text."
IF Bolt = 2   THEN   TextA2 = "IN2 String to test the text."
IF Nut = 1    THEN   TextA3 = "IN3 String to test the text."
IF Nut = 2    THEN   TextA4 = "IN4 String to test the text."

DIM ItemText[4]
ItemText[1] = TextA1
ItemText[2] = TextA2
ItemText[3] = TextA3
ItemText[4] = TextA4
Jochen Suehlo . AC12-27 . MAC OSX 14.4 . WIN11
GDL object creation: b-prisma.de

View solution in original post

2 REPLIES 2
Solution
Jochen Suehlo
Advisor
ItemText[2] is undefined because TEXTA2 is undefined in the default settings.
The best way is to initialize all String Values before they are used.
If you do this at the top of the script, you will have no errors.
 
TextA1 = ""
TextA2 = ""
TextA3 = ""
TextA4 = ""

IF Bolt = 1   THEN   TextA1 = "IN1 String to test the text."
IF Bolt = 2   THEN   TextA2 = "IN2 String to test the text."
IF Nut = 1    THEN   TextA3 = "IN3 String to test the text."
IF Nut = 2    THEN   TextA4 = "IN4 String to test the text."

DIM ItemText[4]
ItemText[1] = TextA1
ItemText[2] = TextA2
ItemText[3] = TextA3
ItemText[4] = TextA4
Jochen Suehlo . AC12-27 . MAC OSX 14.4 . WIN11
GDL object creation: b-prisma.de

Hi Joachim,

 

You are a genius!

 

Thank you, that worked perfectly and is most appreciated!

 

Best regards, Matt

Learn and get certified!