[Closed] Scripted modifier rollout variable weirdness
Not sure if this is an issue with the way I’m creating the modifier or this is how it is supposed to work in max.
I have some objects obj1 and obj2.
I assign my modifier to both obj1 and obj2 (script below)
I can access the text field directly using method 1
obj1.modifiers[#Test_Attributes].sP_txt
obj2.modifiers[#Test_Attributes].sP_txt
I can also access those variables through the rollout and UI using method 2
obj1.modifiers[#Test_Attributes].test_ro.sP_txt.text
obj2.modifiers[#Test_Attributes].test_ro.sP_txt.text
However when using method 2 no matter which object is specified I get the result of the last selected object.
This is not a big issue, the real trouble comes when I try to set the property of the modifier through another script. So running setProperty will set the property of the last selected object no matter which object is specified
-- if obj2 was last selected, this will set the property of obj2 not obj1
setproperty obj1.modifiers[#Test_Attributes] #random_btn true
I’m not sure if this is how it’s supposed to be since the scripted plugin doesn’t store the state of the modifier panel and subsequently the script UI.
Modifier Script:
plugin modifier TestAttributes
name:"Test Attributes"
classID:#(685321,452287)
extends:EmptyModifier
replaceUI:true
(
local test_ro
parameters main rollout:test_ro
(
sP_txt type:#string animatable:false ui:sp_txt default:"[10,-70,5]"
random_btn type:#boolean animatable:false ui:random_btn default:false
on random_btn set val do
(
if val == true then
(
test_ro.sP_txt.text = "[" + (random 0 1000) as string + "," + (random 0 1000) as string + "," + (random 0 1000) as string + "]"
random_btn = false
)
)
)
rollout test_ro "Test Rollout"
(
checkbutton random_btn " Random " checked:false
edittext sP_txt "sP" text:"[10000,-7000,5500]"
)
)
You don’t need the local variable ‘test_ro’ (that is your problem). Delete this local variable. ‘test_ro’ is another ‘property’ of your modifier.
Your sP_txt parameter is linked to the one in the rollout by the ‘ui’ you have specified. Changing one of them changes the other one.
On the event ‘on random_btn set val do’ you can call the sP_txt value by:
- Directly calling it:
sP_txt = "[" + (random 0 1000) as string + "," + (random 0 1000) as string + "," + (random 0 1000) as string + "]"
- Calling the rollout ui:
this.test_ro.sP_txt.text = "[" + (random 0 1000) as string + "," + (random 0 1000) as string + "," + (random 0 1000) as string + "]"
Of course there’s no need to have both the same name.
thanks for your help aaandres,
that fixed most of the issues by using a direct call.
sP_txt = "[" + (random 0 1000) as string + "," + (random 0 1000) as string + "," + (random 0 1000) as string + "]"
The actual script I’m trying to troubleshoot is much bigger and more complex so I’m just breaking out the parts I’m having trouble with.
When calling random_btn I want to also disable a UI element. When accessing anything though the rollout UI it seems the rollout UI is not specific to the object, but either the last selected object or currently selected object.
I updated the script below.
when calling
setproperty obj1.modifiers[#Test_Attributes] #random_btn true
the random numbers are generated for the right object but the checkbox UI is disabled for the currently selected object. It seems like the UI elements are not unique to the object but a variable that stores global max modifier UI state
plugin modifier TestAttributes
name:"Test Attributes"
classID:#(685321,452287)
extends:EmptyModifier
replaceUI:true
(
parameters main rollout:test_ro
(
sP_txt type:#string animatable:false ui:sp_txt default:"[10,-70,5]"
random_btn type:#boolean animatable:false ui:random_btn default:false
on random_btn set val do
(
if val == true then
(
-- below works fine
sP_txt = "[" + (random 0 1000) as string + "," + (random 0 1000) as string + "," + (random 0 1000) as string + "]"
-- accessing through UI will disable the currently selected object's test checkbox
this.test_ro.test_chb.enabled = false
random_btn = false
)
)
)
rollout test_ro "Test Rollout"
(
checkbutton random_btn " Random " checked:false
edittext sP_txt "sP" text:"[10000,-7000,5500]"
checkbox test_chb "disable after random" checked:false
)
)