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.

Tips for saving writing code

jc4d
Expert

Hello

I have a set of hideparameters that change depending on what option is checked (hope it makes sense)

 

Here i have an example in the parameter script:

 

		IF no_shelf_1 = 1 THEN
			HIDEPARAMETER "ShelfStyles_1"
			HIDEPARAMETER "Shelf_1_Bottom_Limit"
		ENDIF
		IF no_shelf_2 = 1 THEN
			HIDEPARAMETER "ShelfStyles_2"
			HIDEPARAMETER "Shelf_2_Bottom_Limit"
		ENDIF
		IF no_shelf_3 = 1 THEN
			HIDEPARAMETER "ShelfStyles_3"
			HIDEPARAMETER "Shelf_3_Bottom_Limit"
		ENDIF

 

 

As you can see in the example above, if I need to add more "IF no_shelf_x" then I have to modify the ShelfStyles_3 to ShelfStyles_x and  Shelf_3_Bottom_Limit to Shelf_x_Bottom_Limit and it is a real pain to do it by hand.

 

So my question is if there is a better way to do this using loops for example?

 

Juan.

2 REPLIES 2
runxel
Legend

Have "no_shelf" as an array parameter, so you can loop over all indices, then do some string manipulating:

 

for i=1 to vardim1(no_shelf)
	if no_shelf[i] then
    	foo = "shelfstyles_" + str("%~", i)
		hideparameter	foo
	endif
next i

 

 

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»

Thank you, I will test it as soon as I get a chance. 😊

Learn and get certified!