[Closed] New subrollout when a button is pressed
How can I add a new subrollout to a rollout every time I press a button in the same rollout?
The variable of the subrollout is the same in the button’s event,how can I change it based on picked object for example ?
I have searched the forums,and found about execute but when I execute the name of the object it outputs the name of the object as a string naturally .
It would be easier if there is obj.name as variable:applause: just kidding.
I forget to mention that it is for a custom attributes modifier and not a floater.
check out rolloutCreator in the maxscript reference.
I’m not sure if this direct link works:
I want to make a space switch ui for my custom rig when I pick the object it creats a slider to control the weight of some controllers,How do I do this?
This is how I tried to do it:
parameters SpcP rollout:SpaceRollout
(
SpcBlnd type:#float ui:MnSpc default:0
objs type:#maxobjecttab tabSizeVariable:true
)
rollout SpaceRollout "SpaceSwitches" width:168 height:550
(
Slider MnSpc "Free/Locked" type:#float range:[0,1,0]
pickbutton AdBtn "Add Object" width:140 height:35
subrollout SbRollout "SbSwitches" width:130 height:200
on AdBtn picked obj do
(
pkobj=nodeTransformMonitor node:obj forwardTransformChangeMsgs:false
append objs pkobj
(
rollout rol1 obj.name
(
slider sld1 "blend:"
)
addSubRollout SbRollout Rol1
/* rci = rolloutCreator obj.name obj.name
rci.begin()
rci.addControl #slider #sld1 "blend:"
rci.end()
addSubRollout SbRollout rci .def */
)
)
)
But then I realized that it won’t stay because every time the rollout is created after selecting, it evaluates the original ui without these sliders and it is not practical to put the whole custom attributes (very large) into the button’ event, isn’t it?
I thought I could put new modifier with every object added instead, that also allows me to delete it.
if i understand your problem right, you need a system to dinamicaly load parameters.
The way i went about it, when i had a similar problem, was to write controls as text stream and then, at a conveniant moment, run it, using “execute” command.
example:
aFloater = newRolloutFloater “Renamer” 300 360
rollout foo “Starter” (
button foo_btn “Get selection names”
subrollout foo_sub width:280
on foo_btn pressed do (
local txt = “rollout foon “Foo names:” width:270 (
“
for i = 1 to selection.count do (
[i] txt += “edittext sel” + i as string + ” text:”” + $.name + “” width:220 align:#right
“
)
for j = 1 to selection.count do (
txt += “on sel” + j as string + ” entered nn do ($[” + j as string + “].name = nn)
” –; foo.foon.sel” + i + “.text =
)
txt += “)
“
txt += “AddSubRollout foo.foo_sub foon
“
execute txt
foo.height = selection.count*30
foo.foo_sub.height = selection.count*30
)
)
addRollout foo aFloater
In this case i put whole of a floater into a txt filestream.
I hope i understood your question well, and am aware, that my method probably isn’t the best way to go about it. it did work for me, though. But it does make your code les readable, which makes debugging a major PITA kind of a task.
or as in your example:
/*
parameters SpcP rollout:SpaceRollout
(
SpcBlnd type:#float ui:MnSpc default:0
objs type:#maxobjecttab tabSizeVariable:true
)
*/
rollout SpaceRollout "SpaceSwitches" width:168 height:550
(
local objs = #()
Slider MnSpc "Free/Locked" type:#float range:[0,1,0]
pickbutton AdBtn "Add Object" width:140 height:35
subrollout SbRollout "SbSwitches" width:130 height:200
on AdBtn picked obj do
(
pkobj=nodeTransformMonitor node:obj forwardTransformChangeMsgs:false
append objs pkobj
(
txt = "rollout " + obj.name + " \"" + obj.name + "\" (
"
txt += "slider " + obj.name + "_sld1 \"blend:\"
"
txt += ")
"
txt += "addSubRollout SpaceRollout.SbRollout " + obj.name + "
"
execute txt
txt = undefined
/*
SpaceRollout.SbRollout.rol1.title = obj.name
rci = rolloutCreator obj.name obj.name
rci.begin()
rci.addControl #slider #sld1 "blend:"
rci.end()
addSubRollout SbRollout rci .def */
)
)
)
if z_floater != undefined then CloseRolloutFloater z_floater
z_floater = newRolloutFloater "trey" 200 525
addRollout SpaceRollout z_floater
i used it as a floater but it should make no difference.
If used in realworld app, there sould be done something, a test or what, about the new rollout’s and slider’s unique variable.name, to avoid a crash due to repeated varnames in case of selecting the same object.