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

Add buttons dynamically

jc4d
Advocate

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

Solution
16 REPLIES 16

jc4d
Advocate

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.

FREE Soffit & Fascia for Rail Tool - https://bit.ly/BIMRithmSoffitandFascia
FREE wall Accessory framing and coverings - bit.ly/BIMRithmWallAccessories
FREE Truss object - https://bit.ly/BIMRithmTrussV1
FREE Custom Tube Object - https://bit.ly/BIMRithmPolyTube
AC 24, Twinmotion current, Windows 11, Msi 10UG with rtx 3070, wacom intuos pro m, Wacom Cintiq Pro 16, razer Tartarus pro.

Thank you, interesting solution I will test it out.

Yves
Booster

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

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

No need to have an IF statement for ui_infield !

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

jc4d
Advocate

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

You just need a for/next loop or two.

FREE Soffit & Fascia for Rail Tool - https://bit.ly/BIMRithmSoffitandFascia
FREE wall Accessory framing and coverings - bit.ly/BIMRithmWallAccessories
FREE Truss object - https://bit.ly/BIMRithmTrussV1
FREE Custom Tube Object - https://bit.ly/BIMRithmPolyTube
AC 24, Twinmotion current, Windows 11, Msi 10UG with rtx 3070, wacom intuos pro m, Wacom Cintiq Pro 16, razer Tartarus pro.

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

Thank you, yes I have an array in a condition if all the shelves are the same, but there is another condition where the shelves can be different, user's choice.

My script works flawless, just not sure if there is a more optimal way on doing it when all the shelves are different.

Solution

not sure if that is what you were looking for...

 

https://drive.google.com/file/d/1N8-0rHlxeE7StJ23wwTwROxMKqIzpGhW/view?usp=drivesdk

AC 22, 24 | Win 10

Yes, exactly what I'm looking after. 👍

Thank you.

 

Here is a quick video of where i took my shelving object

 

FREE Soffit & Fascia for Rail Tool - https://bit.ly/BIMRithmSoffitandFascia
FREE wall Accessory framing and coverings - bit.ly/BIMRithmWallAccessories
FREE Truss object - https://bit.ly/BIMRithmTrussV1
FREE Custom Tube Object - https://bit.ly/BIMRithmPolyTube
AC 24, Twinmotion current, Windows 11, Msi 10UG with rtx 3070, wacom intuos pro m, Wacom Cintiq Pro 16, razer Tartarus pro.

You are using the same hotspot to perform different tasks depending on the direction to where you move it?.

That is fantastic, didn't know that.

I'll post a link in a bit so you can look at it if you are interested.

FREE Soffit & Fascia for Rail Tool - https://bit.ly/BIMRithmSoffitandFascia
FREE wall Accessory framing and coverings - bit.ly/BIMRithmWallAccessories
FREE Truss object - https://bit.ly/BIMRithmTrussV1
FREE Custom Tube Object - https://bit.ly/BIMRithmPolyTube
AC 24, Twinmotion current, Windows 11, Msi 10UG with rtx 3070, wacom intuos pro m, Wacom Cintiq Pro 16, razer Tartarus pro.

Absolutely, very interested on your method.

Still looking?

Browse more topics

Back to forum

See latest solutions

Accepted solutions

Start a new discussion!