Notifications
Clear all

[Closed] Get control over gui elements by dynamic rollout counts

Hello everyone,
I have write a script that builds me for every arch and design material in the scene a rollout with some controls, like diffuse color, sample etc.
I also integrate a mapbutton with that I can change the texture. But now I will change the button text after I have select a bitmap. But this I don’t know how to do, because the rollouts builds dynamical, so the button names are not static.

Here is a part of the script with them I build the rollout:


 for a = 1 to archMtl.count do (
	UIcode = "rollout MaterialSetting_" + a as string + " \"" + archMtl[a].name + "\"
"
	UIcode += "("
	UIcode += "GroupBox grpDiffuse" + a as string + " \"Diffuse" + "\"pos:[4,0] width:151 height:35 
"
	UIcode += "spinner spnLevel" + a as string + " \"Level:" + "\"pos:[40,15] width:45 range:[0.0,1.0," + archMtl[a].diff_weight as string + "]
"
	UIcode += "colorPicker picDiff" + a as string + " \"" + "\"pos:[90,15] width:40 height:15 color:" + archMtl[a].diff_color as string + "
"
	UIcode += "mapButton picMap" + a as string + " \"" + "\"pos:[135,15] width:15 height:15 
"
	UIcode += ")"
	UIcode += "addRollout MaterialSetting_" + a as string + " MaterialRollout"

	execute UIcode
	
	fillPreset archMtl[a]
	)
 

Have you a idea how I can control a button in this situation?

9 Replies

you can get the controls a rollout contains using the <rollout>.controls property

this is an array containing ALL controls in that rollout. Even internal ones like “GroupStartControl” or “GroupEndControl” etc…

you can use that to change the properties off the desired controls without rebuilding the rollout

see more details here

http://docs.autodesk.com/3DSMAX/15/ENU/MAXScript-Help/files/GUID-5DFECB42-C452-457B-BAD4-B07767AE8C9E.htm

Thank you spacefrog for your answer! I use already the controls command. Here for example:
https://github.com/jb-alvarado/ArchAndDesignManager/blob/master/ArchAndDesignManager.ms#L198-L206


 	on GlobalMaterialSetting open do (
 		fillRollout()
 		for i = 1 to archMtl.count do (
 			if archMtl[i].diff_color_map != undefined do (
 				rollArray[i].controls[4].map = archMtl[i].diff_color_map
 				rollArray[i].controls[4].text = "M"
 				)
 			)
 		)
 
 

But with that I only can accesses the controls when I evaluate the hole array.

But here in the screenshot you see that I have there mapbutton where I can pick texturemaps And I want that directly after picking a bitmap the label from the button change. And this don’t work with the controls, or I don’t get it how it will work.

In this way I also can not build a rightclick menu for the mapbutton, because the rollout numbers will change in every scene and I don’t have a stable controls index.

You should use an eventhandler to change the buttons captions when the map gets added

I see you using your own code to build the rollout array, but in such a case with so many rollouts it would IMHO be far better to use the “RolloutCreator.ms” that ships with Max
That way you could create your rollouts and assign eventhandlers to to various elements in a far more flexible manner than you do it now via your own UI code string + exexcute() method

http://docs.autodesk.com/3DSMAX/15/ENU/MAXScript-Help/files/GUID-5FC5036F-E2D7-46C9-9AFA-7B3550B9F254.htm

Though you still can add the code for the eventhandler in your own UI execute string for that specific map button, but i think you’d be better off using “RolloutCreator.ms”

Yes, I think you are right. This was my first experience with a dynamical rollout and I don’t found better examples about it before.

I will try to rewrite my code. But allow me one question more: how can I change then with this method the control name.

Let say I have a array with 5 items and every items stay for a new button name.

This doesn’t work:


   idx = #(1,2,3,4,5)
   
   rci = rolloutCreator "myRollout" "My Rollout"
   rci.begin()
   
   for i in idx do (
   nam = "#myButton_" + i as string
   
   rci.addControl #button nam "My Button"
   rci.addHandler nam #pressed filter:on codeStr:"MessageBox @Isn't this cool@ title:@Wow@"
   	
   )
   createDialog (rci.end())
   

Edit: ok I have it already:

rci.addControl #button (("myButton_"+(i as string)) as name) "My Button"

how about you make fn first for each control and then include it on rollout builder. at least it work for me. Its rough idea but you got the pic , I thing



fn makematerials mat=
(
 -- do something
) 

fn makedoodle =
(
--do doodle thing
)

for a = 1 to archMtl.count do (
	UIcode = "rollout MaterialSetting_" + a as string + " \"" + archMtl[a].name + "\"
"
	UIcode += "("
	UIcode += "GroupBox grpDiffuse" + a as string + " \"Diffuse" + "\"pos:[4,0] width:151 height:35 
"
	UIcode += "spinner spnLevel" + a as string + " \"Level:" + "\"pos:[40,15] width:45 range:[0.0,1.0," + archMtl[a].diff_weight as string + "]
"
	UIcode += "colorPicker picDiff" + a as string + " \"" + "\"pos:[90,15] width:40 height:15 color:" + archMtl[a].diff_color as string + "
"
	UIcode += "mapButton picMap" + a as string + " \"" + "\"pos:[135,15] width:15 height:15 
"

case i of 
(
3:UIcode +="on spnLevel changed value do makematerials mat"
4:UIcode += "on picDiff changed rgb do makedoodle()"
)

	UIcode += ")"
	UIcode += "addRollout MaterialSetting_" + a as string + " MaterialRollout"

	execute UIcode
	
	fillPreset archMtl[a]
	)


that’s a way how to do these things.

fn makeMaterialRollout =
(
	ss  = "rollout params \"\"
"
	ss += "(
"
	ss += "	materialbutton bt \"\" width:180
"
	ss += "	fn setMaterial mat title:on = if iskindof mat Material do
"
	ss += "	(
"
	ss += "		if bt.material != mat do bt.material = mat
"
	ss += "		bt.text = mat.name 	
"
	ss += "		if title do params.title = mat.name 
"
	ss += "		mat
"
	ss += "	)
"
	ss += "	on bt picked mat do setMaterial mat
"
	ss += ")
"
	execute (ss as string)
)
try(closeRolloutFloater floater) catch()
floater = newrolloutfloater "MEdit Materials" 218 300 
for k=1 to 10 do 
(
	rol = makeMaterialRollout()
	addrollout rol floater
	rol.setMaterial meditmaterials[k] 
) 

personally i don’t like rolloutcreator and don’t recommend use it.

Thank you fajar and denisT,
this examples are also nice! I had the impression that the rollout from denisT opens a bit more smooth. Or maybe it is because of the fact that every rollout have only one button. I need to try it in my script.

it will be better (smoother) to create all rollouts first, and after that add them to floater

Yes this I understand, but I think in your example it also create the rollouts on the fly. That is why I was wondering why it open a bit more soft.