[Closed] Monitor Multiple Checkboxes
I’m very new to Maxscript, so forgive me if this is an easy one. I have a bunch of Checkbuttons, any one of which can be pressed at any time. However, I need a way to make it so that when one button is selected, the others become unselected. They are numbered and ready for a for loop or something of the sort.
So what I need is code that says “If any of these buttons are pressed, deselect all of the others.”
Any suggestions?
You can first register an event handler (on myCheckbutton01 changed state do…) for each one of them.
Then call a custom function from each one of these handlers with argument the index of the checkbutton so the function knows which one you mean. Of course, you will have to take into account that sometimes you might UNcheck a checkbox that was checked, in which case you need to decide whether all remain unchecked or a default one (the first?) gets checked.
Alternatively, you can simply use a RadioButtons control which does this automatically.
Here is a POSSIBLE implementation (there is more than one way to skin a … script):
rollout test "Test"
(
checkbutton chk_button01 "Button 01" checked:true
checkbutton chk_button02 "Button 02"
checkbutton chk_button03 "Button 03"
checkbutton chk_button04 "Button 04"
checkbutton chk_button05 "Button 05"
fn updateCheckbuttons theIndex theState =
(
theCheckbuttonsArray = #(chk_button01,chk_button02,chk_button03,chk_button04,chk_button05)
if theState then
for i = 1 to 5 where i != theIndex do theCheckbuttonsArray[i].state = false
else
(
theCheckbuttonsArray[1].state = true
for i = 2 to 5 do theCheckbuttonsArray[i].state = false
)
)
on chk_button01 changed state do updateCheckbuttons 1 state
on chk_button02 changed state do updateCheckbuttons 2 state
on chk_button03 changed state do updateCheckbuttons 3 state
on chk_button04 changed state do updateCheckbuttons 4 state
on chk_button05 changed state do updateCheckbuttons 5 state
)
createDialog test
How about using Radiobutton instead of Checkboxes, only allows you to have one selected at the same time.