GDL
About building parametric objects with GDL.
SOLVED!

Use some values from other value list

jc4d
Expert

Hello,

I have one values{2} list containing some model types and a second values{2} containing all the possible dimensions among all the models.

 

Now, the thing is that depending on the selected model type it could use some of the values sets on the second list.

 

For example, I have 3 model type and the dimensions that all of them altogether could use are 6 different sizes. Now when I choose the first model type, only the first 3 sizes should be displayed in the parameters, if I choose a second model type, then that one will use only the last two sizes from the second list... I really hope all this makes sense.

 

I have setup a starting script, but not sure how to tell to each IF condition to display some values from the main size list.

 

VALUES{2} "model_type" 1,"ORIVENT 51",	2,"ORIVENT 21",	3,"ORIVENT 23"


VALUES{2} "all_base_hgt" 1,"200", 2,"350", 3,"400", 4,"750", 5,"900", 6,"1100"

!!! Problem, how to "call" some of the values from "all_base_hgt" to each IF condition
IF model_type = 1 THEN
	VALUES{2} "base_hgt" 1,"400", 2,"750"
ENDIF

IF model_type = 2 THEN
	VALUES{2} "base_hgt" 1,"400", 2,"750", 3,"900"
ENDIF

IF model_type = 3 THEN
	VALUES{2} "base_hgt" 1,"400", 3,"900"
ENDIF

 

 

Juan

2 ACCEPTED SOLUTIONS

Accepted Solutions
Solution
runxel
Legend

For values lists based on another value list you can do some sneaky stuff!

 

values{2} "modeltype",
			1, "Model 1",
			2, "Model 2"

dict cs
cs.sizes[1].s[1] = 100
cs.sizes[1].s[2] = 200
cs.sizes[2].s[1] = 150
cs.sizes[2].s[2] = 300
cs.sizes[2].s[3] = 450

values "sizes" cs.sizes[modeltype].s

 

A small breakdown of whats happening in this brilliant hack (brilliant because it's working due a nice language feature, the DICT, that founds its way into GDL):

We declare the models and assign a number to them with values{2}, which we will then use as an index for the first level of the dict which happens to be an array. Luckily for us you can stuff an array inside the array (here called just "s"). So you'd put all the applicable sizes into "s".

A last "values" command and you're good to go. Achieving a lot in a few elegant lines of code.

Lucas Becker | AC 27 on Mac | Author of Runxel's Archicad Wiki | Editor at SelfGDL | Developer of the GDL plugin for Sublime Text |
«Furthermore, I consider that Carth... yearly releases must be destroyed»

View solution in original post

Solution

Another take on the case with very easy adjustments:

 

values{2} "modeltype",
	1, "Model 1",
	2, "Model 2"

dict cs
cs.sizes[1].s[1] = 100
cs.sizes[1].t[1] = "Short"
cs.sizes[1].s[2] = 200
cs.sizes[1].t[2] = "Tall"
cs.sizes[2].s[1] = 150
cs.sizes[2].t[1] = "Grande"
cs.sizes[2].s[2] = 300
cs.sizes[2].t[2] = "Venti"
cs.sizes[2].s[3] = 450
cs.sizes[2].t[3] = "Just normal coffee pls"

values{2} "sizes",
	cs.sizes[modeltype].s, cs.sizes[modeltype].t

 

Since the user never sees the index numbers from modeltype there never should be a case where they are not consecutive. But if they are: As long they are integers and bigger than zero it should be fine. Archicad would fill the missing gaps between in the array.

Lucas Becker | AC 27 on Mac | Author of Runxel's Archicad Wiki | Editor at SelfGDL | Developer of the GDL plugin for Sublime Text |
«Furthermore, I consider that Carth... yearly releases must be destroyed»

View solution in original post

16 REPLIES 16
Barry Kelly
Moderator

You don't need the parameter 'all_base_hgt' as you are setting the parameter 'base_hgt', and that seems to be working just fine depending on the model you choose.

 

BarryKelly_0-1666682978622.pngBarryKelly_1-1666683032371.png

 

Barry.

One of the forum moderators.
Versions 6.5 to 27
Dell XPS- i7-6700 @ 3.4Ghz, 16GB ram, GeForce GTX 960 (2GB), Windows 10
Lenovo Thinkpad - i7-1270P 2.20 GHz, 32GB RAM, Nvidia T550, Windows 11

Thanks, yeah that's how I got it working in the beginning, but let's say that the value in the second values{2} list changes, I would have to go throught all the IF to update them, and I would like to have a more parametric way to deal with. Hope it makes sense.

Edited the code here with the right comments on what I'm going after:

VALUES{2} "model_type" 1,"ORIVENT 51",	2,"ORIVENT 21",	3,"ORIVENT 23"


VALUES{2} "all_base_hgt" 1,"200", 2,"350", 3,"400", 4,"750", 5,"900", 6,"1100"


IF model_type = 1 THEN
	!!!!Access here the index 1 and 3 from all_base_hgt
ENDIF

IF model_type = 2 THEN
	!!!!Access here the index 1,2 and 3 from all_base_hgt
ENDIF

IF model_type = 3 THEN
	!!!!Access here the index 5 and 6 from all_base_hgt
ENDIF

I don't think you can pick and choose values from a value list to use in another value list.

Maybe you need to create an array to store the values and then populate the value lists from the array values?

 

Barry.

One of the forum moderators.
Versions 6.5 to 27
Dell XPS- i7-6700 @ 3.4Ghz, 16GB ram, GeForce GTX 960 (2GB), Windows 10
Lenovo Thinkpad - i7-1270P 2.20 GHz, 32GB RAM, Nvidia T550, Windows 11

Now I got lost 😅.

Is there any example out there in the wild that I can check?

 

Juan

Lingwisyer
Guru

This seems very round about... Why not just use VALUES instead that point at variables? Then have your use cases later point at those same variables, rather than trying to make the descriptor a variable, which is not nesessarily actually relevant later. In your current case base_hgt = 1 might actually be resulting in using a value of 1100 instead of 200. Usually you would be using VALUES{2} to provide a name of some options such as a type of joint type or skirting type.

 

v1 = 0.200
v2 = 0.350
v3 = 0.400
v4 = 0.750
v5 = 0.900
v6 = 1.100

IF model_type = 1 THEN
	VALUES "base_hgt" v3, v4
ENDIF

IF model_type = 2 THEN
	VALUES "base_hgt" v3, v4, v5
ENDIF

IF model_type = 3 THEN
	VALUES "base_hgt" v3,  v5
ENDIF

 

 

Ling.

AC22-23 AUS 7000Help Those Help You - Add a Signature
Self-taught, bend it till it breaksCreating a Thread
Win10 | R5 2600 | 16GB | GTX1660 
jc4d
Expert

That's great workaround, the idea behind using VALUES{2} is that the designers always change their mind on the therminology used in the parameters, so having control over the names on a centralized way has saved me huge amount of hours.

 

I will give it a spin to your solution to see how it adapts to my idea 👍.

 

What I ended up doing (not to my liking, keeping track of one change into so many places) is this:

jc4d_0-1666688166230.png

 

Juan

 

jc4d
Expert

I was trying to use the subroutine way, but couldn't wrap my head around 😂

If you use only dimensions, I think Lingwisyer suggestion to use simple value is the best. Because looking at your screenshots base_hgt has same int value that stands for different dimensions...

If you do want to use values{2} I'd try to use "integer variables" instead of actual integer numbers.

 

for example:

 

Master script:

base200=200

base400=400

...and so on it doesn't have to be only 1,2,3,...

tbh redundant if basically difference is only dimensions (can skip it)

 

parameter script:

values{2} "base_hgt" base200, "200", base400, "400",...

or straight if skipped master

values{2} "base_hgt" 200, "200", 400, "400"

 

in that case chance of mistake is lower. plus you always can make nice conditions (because "base_hgt" has integer type), kinda

if base_hgt = 400 then _code_

 

just be careful when use that variable base_hgt for modelling (because of picking actual values 200, 400, not straight forward 1,2,3 you can use it there too) not forget to multiply by 0.001

 

AC 22, 24 | Win 10
Solution
runxel
Legend

For values lists based on another value list you can do some sneaky stuff!

 

values{2} "modeltype",
			1, "Model 1",
			2, "Model 2"

dict cs
cs.sizes[1].s[1] = 100
cs.sizes[1].s[2] = 200
cs.sizes[2].s[1] = 150
cs.sizes[2].s[2] = 300
cs.sizes[2].s[3] = 450

values "sizes" cs.sizes[modeltype].s

 

A small breakdown of whats happening in this brilliant hack (brilliant because it's working due a nice language feature, the DICT, that founds its way into GDL):

We declare the models and assign a number to them with values{2}, which we will then use as an index for the first level of the dict which happens to be an array. Luckily for us you can stuff an array inside the array (here called just "s"). So you'd put all the applicable sizes into "s".

A last "values" command and you're good to go. Achieving a lot in a few elegant lines of code.

Lucas Becker | AC 27 on Mac | Author of Runxel's Archicad Wiki | Editor at SelfGDL | Developer of the GDL plugin for Sublime Text |
«Furthermore, I consider that Carth... yearly releases must be destroyed»