We value your input!
Please participate in Archicad 28 Home Screen and Tooltips/Quick Tutorials survey

Libraries & objects
About Archicad and BIMcloud libraries, their management and migration, objects and other library parts, etc.

Retrieving parameter value with parameter name as string

Anonymous
Not applicable
I am trying to use a string as a parameter reference:

I have a parameter called
param_1
which is a boolean variable
I then generate the parameter name in a loop
ie.
	
i = 0
FOR i=1 TO 6 STEP 1
	mystring = 'param_' + str(i,1,0)
NEXT i
I then want to use the generated param name in the same loop
( mystring = "param_1" )
(which does not work)
	
i = 0
FOR i=1 TO 6 STEP 1
	mystring = 'param_' + str(i,1,0)

        if mystring = 1 Then
                            ! // code related to if checkbox is checked (TRUE/ON/1)
		else
                            ! // code related to if checkbox is NOT checked (FALSE/OFF/0)
		endif
NEXT i
The code below does work!!
	
i = 0
FOR i=1 TO 6 STEP 1
	mystring = 'param_' + str(i,1,0)

        UI_INFIELD mystrng, base_posx, base_posy, 20, 20

NEXT i


Given that I can use the generated parameter name with the UI_INFIELD command, I figured there must be a way to use it in an IF statement.
Could anyone point me in the right direction please?
2 REPLIES 2
Bruce
Advisor
Matrices are your friend in this situation. You can't use a loop to create a variable name (as you can in other languages), but you can populate and query / test the contents of a matrix.

DIM arrayName[] is how you declare (or DIM arrayName[][] for a 2-dimension array)

Hope this helps.
Bruce Walker
Barking Dog BIM YouTube
Mindmeister Mindmap
-- since v8.1 --
AC27 5060 INT Full | Windows 11 64 Pro | 12th Gen Intel i7-12700H 2.30 GHz | 64 Gb RAM | NVIDIA GeForce RTX 3060 32 Gb
Anonymous
Not applicable
Bruce wrote:
Matrices are your friend in this situation. You can't use a loop to create a variable name (as you can in other languages), but you can populate and query / test the contents of a matrix.

DIM arrayName[] is how you declare (or DIM arrayName[][] for a 2-dimension array)

Hope this helps.
Thanks for this Bruce,
Ended up following this advice and just passing all the values from the parameters into an array that could be looped through.

It's a shame GDL can't handle parsing strings as param names, this work around works though!