GDL
About building parametric objects with GDL.
SOLVED!

How to create a list from an array

GDL Enthusiast
Advocate

Hi,

 

I have the following code that creates an array. When I go to the UI preview window, it results in an array dialogue (see image 1). Is there a way to make it into a dropdown list instead? I can do it with parameter lists but I was hoping I could do it with arrays, but they seem super complex...

 

!! Master Script

 

DIM Test_Nam[5]
Test_Nam[1] = `Option 1`
Test_Nam[2] = `Option 2`
Test_Nam[3] = `Option 3`
Test_Nam[4] = `Option 4`
Test_Nam[5] = `Option 5`

PARAMETERS Test_Nam[1] = Test_Nam[1]
PARAMETERS Test_Nam[2] = Test_Nam[2]
PARAMETERS Test_Nam[3] = Test_Nam[3]
PARAMETERS Test_Nam[4] = Test_Nam[4]
PARAMETERS Test_Nam[5] = Test_Nam[5]

values{2} "Test_Nam", 0, "Option 1",
1, "Option 2",
2, "Option 3",
3, "Option 4",
4, "Option 5"

 


!! UI Script

ui_infield{2} "Test_Nam", 110, 100, 100, 160

 

My hope is to declare an array and then have the User Interface select an item from that array.

 

Many thanks,

 

From Matt


Image 1.PNG

2 ACCEPTED SOLUTIONS

Accepted Solutions
Solution
Pertti Paasky
Expert

Try this:

DIM _Test_Nam[5] , numbers[5]
_Test_Nam[1] = `Option 1`
_Test_Nam[2] = `Option 2`
_Test_Nam[3] = `Option 3`
_Test_Nam[4] = `Option 4`
_Test_Nam[5] = `Option 5`
numbers[1]=1
numbers[2]=2
numbers[3]=3
numbers[4]=4
numbers[5]=5

 

values{2} "Test_Nam", numbers, _Test_Nam
- AC-24 FIN - WIN 10 - HP Zbook -
“A winner is just a loser who tried one more time.”
George M. Moore, Jr.

View solution in original post

Solution
Jochen Suehlo
Moderator

If you want to use a general code, I recommend declaring the array values in the master script and applying them in a simple way in the parameter script and interface script in the commands. Here is an example:

 

! Master-Script

DIM _einheit_V_text[], _einheit_V_pic[], _einheit_V_value[]
i = 1
_einheit_V_text[i] = "Kubikmeter" : _einheit_V_pic[i] = "" : _einheit_V_value[i] = i : i = i + 1
_einheit_V_text[i] = "Liter" : _einheit_V_pic[i] = "" : _einheit_V_value[i] = i : i = i + 1
_einheit_V_text[i] = "Kubikzentimeter" : _einheit_V_pic[i] = "" : _einheit_V_value[i] = i : i = i + 1
_einheit_V_text[i] = "Kubikmillimeter" : _einheit_V_pic[i] = "" : _einheit_V_value[i] = i : i = i + 1
_einheit_V_text[i] = "Kubikfuß" : _einheit_V_pic[i] = "" : _einheit_V_value[i] = i : i = i + 1
_einheit_V_text[i] = "Kubikzoll" : _einheit_V_pic[i] = "" : _einheit_V_value[i] = i : i = i + 1
_einheit_V_text[i] = "Kubikyards" : _einheit_V_pic[i] = "" : _einheit_V_value[i] = i : i = i + 1
_einheit_V_text[i] = "Gallone" : _einheit_V_pic[i] = "" : _einheit_V_value[i] = i : i = i + 1

! Parameter-Script

VALUES{2} "int_einheit_V", _einheit_V_value, _einheit_V_text 

! Interface-Script

UI_OUTFIELD "", 10, 10, 100, 20
UI_INFIELD{3} "int_einheit_V", 120, 10, 100, 20,
8, "",
0, 0, 0, 0, 0, 0,
_einheit_V_pic, _einheit_V_text, _einheit_V_value

 

As you see, you can shorten the code of VALUES{2}  and UI_INFIELD{3}

Jochen Suehlo . AC12-27 . MAC OSX 14.4 . WIN11
GDL object creation: b-prisma.de

View solution in original post

8 REPLIES 8

It is possible, I believe I ended up finding what I needed to know on alternative sites, that being said I'll have to open things up but I'll post some examples after I finish some work if someone else doesn't post in the meantime 

Solution
Pertti Paasky
Expert

Try this:

DIM _Test_Nam[5] , numbers[5]
_Test_Nam[1] = `Option 1`
_Test_Nam[2] = `Option 2`
_Test_Nam[3] = `Option 3`
_Test_Nam[4] = `Option 4`
_Test_Nam[5] = `Option 5`
numbers[1]=1
numbers[2]=2
numbers[3]=3
numbers[4]=4
numbers[5]=5

 

values{2} "Test_Nam", numbers, _Test_Nam
- AC-24 FIN - WIN 10 - HP Zbook -
“A winner is just a loser who tried one more time.”
George M. Moore, Jr.
runxel
Hero

For a nice display in the UI you should use ui_infield{3} with 8 as method:

 

ui_infield{3} "myParam", posx, posy, inFldWdt, inFldHgt,
 		8, "", 3, 1, 0, 0, 0, 0,
 		"", "Option 1", 1,
 		"", "Option 2", 2,
 		"", "Option 3", 3
   .....
Lucas Becker | AC 27 on Mac | Graphisoft Insider Panelist | Author of Runxel's Archicad Wiki | Editor at SelfGDL | Developer of the GDL plugin for Sublime Text | My List of AC shortcomings & bugs | I Will Piledrive You If You Mention AI Again |

POSIWID – The Purpose Of a System Is What It Does /// «Furthermore, I consider that Carth... yearly releases must be destroyed»
Solution
Jochen Suehlo
Moderator

If you want to use a general code, I recommend declaring the array values in the master script and applying them in a simple way in the parameter script and interface script in the commands. Here is an example:

 

! Master-Script

DIM _einheit_V_text[], _einheit_V_pic[], _einheit_V_value[]
i = 1
_einheit_V_text[i] = "Kubikmeter" : _einheit_V_pic[i] = "" : _einheit_V_value[i] = i : i = i + 1
_einheit_V_text[i] = "Liter" : _einheit_V_pic[i] = "" : _einheit_V_value[i] = i : i = i + 1
_einheit_V_text[i] = "Kubikzentimeter" : _einheit_V_pic[i] = "" : _einheit_V_value[i] = i : i = i + 1
_einheit_V_text[i] = "Kubikmillimeter" : _einheit_V_pic[i] = "" : _einheit_V_value[i] = i : i = i + 1
_einheit_V_text[i] = "Kubikfuß" : _einheit_V_pic[i] = "" : _einheit_V_value[i] = i : i = i + 1
_einheit_V_text[i] = "Kubikzoll" : _einheit_V_pic[i] = "" : _einheit_V_value[i] = i : i = i + 1
_einheit_V_text[i] = "Kubikyards" : _einheit_V_pic[i] = "" : _einheit_V_value[i] = i : i = i + 1
_einheit_V_text[i] = "Gallone" : _einheit_V_pic[i] = "" : _einheit_V_value[i] = i : i = i + 1

! Parameter-Script

VALUES{2} "int_einheit_V", _einheit_V_value, _einheit_V_text 

! Interface-Script

UI_OUTFIELD "", 10, 10, 100, 20
UI_INFIELD{3} "int_einheit_V", 120, 10, 100, 20,
8, "",
0, 0, 0, 0, 0, 0,
_einheit_V_pic, _einheit_V_text, _einheit_V_value

 

As you see, you can shorten the code of VALUES{2}  and UI_INFIELD{3}

Jochen Suehlo . AC12-27 . MAC OSX 14.4 . WIN11
GDL object creation: b-prisma.de

Hi Pertti,

 

That is such a great solution, and it produces the drop down list perfectly. I had no idea I could declare more than one array on the same line until I saw it here and in Jochen's response. So much knowledge you all have!!! Thank you so much Pertti, from Matt

Hi Jochen,

 

This is very cool, an expandable solution with clean scripting - very fun! Thank you so much for your answer and elegant coding. I now can have fun with arrays! Many thanks Jochen from Matt

Thank you Runxel, I do like both the infield{2} standard and the infield{3} with method 8 option for visual appearance. 95% of my battle is just getting the code to work! Wishing you all the best, from Matt

Thank you Seneca, most appreciate your being available. Several great solutions below from Pertti, Jochen. Wishing you all the best, Matt