[Closed] Dynamic UI
Here’s problem. Script need to create sliders for face poses, but script don’t know how many poses it need to create before it reads that information from file. So script should create UI dynamicly. How I can create UI elements dynamicly? And script is scripted modifier if that makes any difference.
I just found very interesting function call rolloutCreator(). I guess than I can do this with it.
So now I can create dynamic UI with rolloutCreator() function, but for storing values I need Custom Attribute. How to create those dynamicly.
posesCA = attributes posesData
(
rollout main "Poses"
(
subrollout child "Weights" height:200
on main open do
(
--Create the dynamic rollout
rci = rolloutCreator "posesRollout" "Weights"
rci.begin()
for i=1 to poses.count do
(
local nname = ("edit_"+ (i as string)) as name
rci.addControl #slider nname "Test" paramStr:"text:\"Test\""
)
rci.end()
addSubRollout (main.child) posesRollout
)
)
)
Here is what I have done for this far.
But I can’t add something like this to code above becouse it won’t work.
parameters params rollout:main
(
for i=1 to poses.count do
(
execute ("pose"+(i as string)+" type:#float ui:edit_"+(i as string)+" default:0.0
")
)
)
Can I do what code above try to do in some other way?
One idea could be (if possible). I do floatTab variable
myAtt = Attributes myCA
(
parameters main rollout:params
(
aMyArray type:floatTab tabSizeVariable:true
)
rollout params "My Rollout"
(
...
)
)
But can I assign aMyArray items to UI components after when it is created?
Ok. I got this working with execute command. I ofcourse try this allready, but just now I realize than execute dosen’t see to local scope :(. There’s my bug. So if you use variables with execute make sure than it is in global variable scope.
currently in max the only way to create dynamic paramters is to create a string containing the ca def and then execute it
e.g.
secondspn == true
–secondspn == false
strg = “attributes myattrib
“
strg+=”(
“
strg+=“parameters myparm rollout:myroll
“
strg+=”(
“
strg+=”param1 type:#float ui:spn1
“
if secondspn == true then strg+=“param2 type:#float ui:spn2
“
strg+=”)
“
strg+=“rollout myroll “rollout”
“
strg+=”(
“
strg+=“spinner spn1 “spinner1” range:[-10,10,0]
“
if secondspn == true then strg+=“spinner spn2 “spinner2” range:[-10,10,0]
“
strg+=”)
“
strg+=”)
“
newCA = execute strg
custattributes.add $ newCA
mark