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

GDL
About building parametric objects with GDL.
SOLVED!

Add buttons dynamically

jc4d
Expert

Hello,

 

I would like to add a button depending on the amount that is selected from the list of values.

For example, in Parameters I have: 

VALUES "Shelf_Amount", 1, 2, 3, 4, 5, 6, 7

If I select 1 from the list, one buttom will be added, if I select 2, then two buttons will be added and so on. The idea behind this is that each button will control something different, like using a different gosub depending on which button is pushed.

 

I have managed to add a simple button on the UI, but not sure how to do it in a dynamically way and with a incremental name per button. I thought that adding the variable name + 1 would do the trick, but did failed.

 

Master:

Button_Name = "Test"

 

Interface:

UI_BUTTON UI_FUNCTION, Button_Name, 0, 0, 150, 50

 

Juan.

1 ACCEPTED SOLUTION

Accepted Solutions
Solution
16 REPLIES 16
jc4d
Expert

I managed to create (for now) an outfield depending on the value amount, the problem now is that the items are overlaping and not being added with an offset. So I "forced" the y position of each row but I don't know if there is a more modular way to do it.

_pageStartY = 5
_yCurr		= _pageStartY
_dy			= 24
_infHeight 	= 19
_outfHeight = 15
_offsetY	= 4

_infWidth = 90
_infWidthShort = 54
_x1	= 0
_x4	= 210
_x2	= _x4 - _infWidth
_x3	= _x4 - _infWidthShort

_xSeparator = 220

_x5 = _xSeparator + 10
_x6 = 315

ui_outfield `No. of Modules`,	_x1, _yCurr,				_x3-_x1-2,	_outfHeight
ui_infield{3} "nModule",		_x3, _yCurr - _offsetY,	_x4-_x3,		_infHeight,
	8, "",
	0, 0, 0, 0, 0, 0,
	0, `1`,	1,
	0, `2`,	2,
	0, `3`,	3,
	0, `4`,	4,
	0, `5`,	5,
	0, `6`,	6	ui_tooltip `No. of Modules`
_yCurr = _yCurr + _dy

ui_outfield `Module 1`,	_x5, _yCurr,	_x6-_x5-2,	_outfHeight

IF nModule > 1 THEN
		ui_outfield `Module 2`,	_x5, _yCurr + _dy,	_x6-_x5-2,	_outfHeight
ENDIF

IF nModule > 2 THEN
		ui_outfield `Module 3`,	_x5, _yCurr + _dy*2,	_x6-_x5-2,	_outfHeight
ENDIF

IF nModule > 3 THEN
		ui_outfield `Module 4`,	_x5, _yCurr + _dy*3,	_x6-_x5-2,	_outfHeight
ENDIF

IF nModule > 4 THEN
		ui_outfield `Module 5`,	_x5, _yCurr + _dy*4,	_x6-_x5-2,	_outfHeight
ENDIF

IF nModule > 5 THEN
		ui_outfield `Module 6`,	_x5, _yCurr + _dy*5,	_x6-_x5-2,	_outfHeight
ENDIF

 

 

 

 

 

 
 

 

 

 
 

 

 

You can add a number to a name using a loop. But you have to convert that number to a string and then add it on each new loop.

Yves
Advocate

Hello,
Here is a simpler solution in my opinion 

!!!!!Parameter Integer
VALUES{2} "nModule" 1,"Module 1",
2, "Module 2",
3, "Module 3",
4, "Module 4",
5, "Module 5",
6, "Module 6"


UI_INFIELD{3} "nModule", 0, 50, 110, 15,
8, "", 6, 1, 0, 0, 0, 0,
1, "Module 1",1,
2, "Module 2", 2,
3, "Module 3",3,
4, "Module 4", 4,
5, "Module 5",5,
6, "Module 6", 6

 

Yves Houssier
Belgium
Archicad 19 -> 24
iMac - Mac Os 10,13

Thank you, interesting solution I will test it out.

Thanks, but there is no need to have an IF statement for the ui-infield?

jc4d
Expert

I ended up creating 6 different values one for each option since each one of them can have different object.

 

Everything works as it should be, but not sure if this is the most optimal way to handle it, mostly because the modularity. I meant, if I add 10 shleves amount, then I would need to add manually as many "Shelfstyles_n" values as needed and then add to the interface as many IF statements as needed as well.

 

Better a picture than thousand words :):

Interface:

UI_OUTFIELD `Shleves Amount`, 0, 30, 65, 15
UI_INFIELD{3} "nShelves", 70, 25, 54, 19,
	8, "",
	0, 0, 0, 0, 0, 0,
	0, `1`,	1,
	0, `2`,	2

IF Shelf_Type = 0 THEN
	UI_INFIELD{3} "ShelfStyles_1", 225 , 25, 83, 35,
			2, 2, 6, 5,			! type chooser pict
			130,102,100,90,
			1, `Style 1`, 1,
			2, `Style 2`, 2,
			3, `Style 3`, 3,
			4, `Style 4`, 4,
			5, `Style 5`, 5,
			6, `Style 6`, 6

	IF nShelves > 1 THEN
			UI_INFIELD{3} "ShelfStyles_2", 225, 65,	83, 35,
					2, 2, 6, 5,			! type chooser pict
					130,102,100,90,
					1, `Style 1`, 1,
					2, `Style 2`, 2,
					3, `Style 3`, 3,
					4, `Style 4`, 4,
					5, `Style 5`, 5,
					6, `Style 6`, 6
	ENDIF
ENDIF

Parameters:

VALUES "nShelves", 1, 2
VALUES "ShelfStyles_1" 1,2,3,4,5,6
VALUES "ShelfStyles_2" 1,2,3,4,5,6

 

 

Juan

No need to have an IF statement for ui_infield !

Yves Houssier
Belgium
Archicad 19 -> 24
iMac - Mac Os 10,13

You just need a for/next loop or two.

Peter Baksa
Graphisoft
Graphisoft

If all your shelf styles are the same, you can use an array parameter.

 

VALUES "ShelfStyles" 1,2,3,4,5,6

for i ...
    UI_INFIELD{3} ShelfStyles[i], ...

 

This simplifies the UI commands, however you can't use LOCK, HIDEPARAMETER and GLOB_MODPAR_NAME on individual elements of an array parameter. If you need those, create the parameter name with STR functions in the loop.

Péter Baksa
Software Engineer, Library as a Platform
Graphisoft SE, Budapest