cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

The 2025 Technology Preview Program is now live. Join today!

GDL
About building parametric objects with GDL.

How to control value of VALUES{2} through an IF statement?

Bilkins
Contributor

Hi, this is related to a previous post I've made: Link 

Sorry if this is a double post, but the previous post was technically solved.

 


I have a script where the A and B dimensions are based on two VALUES{2} lists with length parameters.

 

I would like the value of VALUES{2} for the B-dimensions to be dependent on VALUES{2} of the A-dimension through an IF statement. Is this possible? I keep getting error messages regarding parameter types with variations of the following parameter  script:

 

VALUES{2} "size" 2.0, "min", 
5.0, "max"

VALUES{2} "width" size*2, "minwidth",
size*5, "maxwidth"

LOCK "A", "B"

IF size= "max" THEN
width = "maxwidth"
ELSE
width = "minwidth"
ENDIF

A=size
B=width
PARAMETERS A=A, B=B

 

26.7004 NOR │ Win 11 Enterprise x64 ● Intel 9 185H @ 2.30GHz ● 64GB ● Nvidia RTX 3000 Ada
7 REPLIES 7
NMK195
Participant

Hello!

I am not very proficient in English, so I will use ChatGPT to help translate the message below. If anything is unclear, please feel free to ask me for clarification.

Regarding your code:

For values{2}, "min" and "max" are only display texts, not actual parameter values. Therefore, setting size = "max", width = "maxwidth", or width = "minwidth" is incorrect in terms of parameter types.

Suggested correction:

 

VALUES{2} "size" 2.0, "min", 
5.0, "max"

VALUES{2} "width" size*2, "minwidth", 
size*5, "maxwidth"

LOCK "A", "B"

EPS = 0.00001
IF abs(size-2) < EPS THEN 
parameters width = 4
ELSE
parameters width = 25
ENDIF

A=size
B=width
PARAMETERS A=A, B=B
runxel
Hero

As NMK195 said: The "stringified" representation is just there for the user, that's the whole poinf of using it.

However in your particular case it might make sense to actually check for "min" and "max", since the numbers might change.

There is hope: you can use this command parvalue_description ("size") to retrieve the string representation.

I myself would still not use it since string comparisons are very costly and it is more elegant to just use a local definition like this (I use all uppercase for constants to better distinguish):

 

!//--in Master script:
EPS = 0.00001
SIZE_MIN = 2.0
SIZE_MAX = 5.5

!//--in Param script:
values{2} "size",
    SIZE_MIN, "min",
    SIZE_MAX, "max"

!//--in 2D/3D then:
!// be aware of floating point inaccuracy !
if abs(size-SIZE_MIN) < EPS then
    !.... do whatever
endif

 

Happy coding!

 

Lucas Becker | AC 27 on Mac | Graphisoft Insider Panelist | Akroter.io – high-end GDL objects | 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»
Domagoj Lukinic
Booster

Hi, 

I used this in my last script:

if n>0 then
	values "A",A_half*2
	values "B",range [1,]
	else 
	values "B",range [1,]
	parameters A=B
endif

Before this IF the A and B sizes are not defined. 

 

Hi,

Your 'values' command has an extra comma
the correct format should be as follows:

if n>0 then
	values "A" A_half*2
	values "B" range [1,]
	else 
	values "B" range [1,]
	parameters A=B
endif

 

Hi,

VALUES "parameter_name" [,]value_definition1 [, value_definition2, ...]

you can put comma in "values", its optional.

So it is not an error, it is a matter of preference as far as I know  🤷‍

 

 

Hi.

 

You're right, I've never used a comma after 'values' before, so I thought it was incorrect. I tried it again and saw that there's nothing wrong with the code above — the error might be in another line that you didn’t mention earlier. If possible, please upload the file here so everyone can check it more accurately.

 

the values{2} can take arrays as input, and the ui_infields can take arrays as well. (I know the question was anout values(2}, but those 2 topics are connected.

 

if I have to have dynamic input in either plain entry of the parameter of than in the UI i do something like that:

prepare 3 arrays: 1 for indexes, 2 for strings, 3 for ui pictures in the master script

i put every possible entry for those arrays.

than in the parameter script I double the arrays with different names but with conditional jumps (if.. then...) for the entries that are dynamic

than either I use values with indexes from parameter script or values{2} with indexes and strings (both parameters from parameter script.

Finally in the UI in the ui_infield command I use the arrays defined in master script to avoid possible missing entries on some situations - I had all parametric defined arrays in masterscript without the "full" ones, but in some situations that setup could make errors in the UI.