Notifications
Clear all

[Closed] Problem with CheckButtons …. Please help

I am facing a problem with checkbuttons :

suppose we have 3 checkbuttons. One of the checkbuttons, when pressed or depressed,determines the state of the other 2 to be true or false. These other 2 guys , in turn have event handlers to select or deselect certain objects.

For some reason, when we change the state of a checkbutton through a script instead of actually clicking the button, the event handlers for that button are not called. Can someone help me with this please?
sample script:


rollout unnamedRollout "Untitled" width:162 height:300
( 
checkbutton ckb2 "CheckButton" pos:[54,28] width:24 height:19 
checkbutton ckb3 "CheckButton" pos:[55,65] width:26 height:24 
checkbutton ckb4 "CheckButton" pos:[25,126] width:83 height:23 
 
	on ckb2 changed state do
	(
		if (ckb2.checked == true) then 
		(selectmore $dummy01)
		else (deselect $dummy01)
	)
 
	on ckb3 changed state do
	(
	 if (ckb3.state == true) then (selectmore $dummy02)
	 else (deselect $dummy02)
	 )
 
	on ckb4 changed state do
	(
	 if ckb4.state == true then
		 (
			ckb2.checked = true
			ckb3.checked = true	
		 )
	 else 
		 (
			ckb2.checked = false
			ckb3.checked = false
		 )
 
	)
 
)
 
createdialog unnamedRollout
 

thanks galagast, for showing me how to get the scrollable code window within a post.

4 Replies
1 Reply
(@bobo)
Joined: 11 months ago

Posts: 0

When changing a state of a checkbutton through a script, MAXScript does not call the event handler. As mentioned by galagast, you can call the ebent handler as a function though. But calling the event handler does NOT change the state of the checkbox, so you have to do both!

  rollout unnamedRollout "Untitled" width:162 height:300
 ( 
 local obj1 = $dummy01
 local obj2 = $dummy02
 checkbutton ckb1 "CheckButton" pos:[54,28] width:24 height:19 checked:obj1.isSelected 
 checkbutton ckb2 "CheckButton" pos:[55,65] width:26 height:24 checked:obj2.isSelected
 checkbutton ckb3 "CheckButton" pos:[25,126] width:83 height:23 
 
 --select/deselect based on the state value 
 on ckb1 changed state do if state then selectMore obj1 else deselect obj1
 on ckb2 changed state do if state then selectMore obj2 else deselect obj2
 on ckb3 changed state do
 (
   ckb1.changed (ckb1.checked = state) --call the change handler, but first change the state using the current value
   ckb2.changed (ckb2.checked = state) --then use the result as argument to the handler...
 )
 )--end rollout
  
 createdialog unnamedRollout

maybe you could try calling in the button as a function itself…

e.g.


ckb2.changed true
ckb3.changed true

hope this helps!

thanks guys …
thats was very helpful.

Another solution would be to make the buttons execute a local function and the ‘over’ button calls those two functions… i.e.

rollout unnamedRollout "Untitled" width:162 height:300
 ( 
 checkbutton ckb2 "CheckButton" pos:[54,28] width:24 height:19 
 checkbutton ckb3 "CheckButton" pos:[55,65] width:26 height:24 
 checkbutton ckb4 "CheckButton" pos:[25,126] width:83 height:23 
 
 function ckb2_func =
 	(
 		if (ckb2.checked == true) then 
 		(selectmore $dummy01)
 		else (deselect $dummy01)	
 	);
 	
 function ckb3_func =
 	(
 		if (ckb3.checked == true) then 
 		(selectmore $dummy02)
 		else (deselect $dummy02)	
 	);
 
 	on ckb2 changed state do
 	(
 	ckb2_func();
 	)
  
 	on ckb3 changed state do
 	(
 	 ckb3_func();
 	 )
  
 	on ckb4 changed state do
 	(
 	 if ckb4.state == true then
 		 (
 			ckb2.checked = true
 			ckb3.checked = true
 		 )
 	 else 
 		 (
 			ckb2.checked = false
 			ckb3.checked = false
 		 )
 		 
 	ckb2_func();
 	ckb3_func();
  
 	)
  
 )
  
 createdialog unnamedRollout

To make it even more efficient, however a little more tricky, try:

rollout unnamedRollout "Untitled" width:162 height:300
 ( 
 checkbutton ckb2 "CheckButton" pos:[54,28] width:24 height:19 
 checkbutton ckb3 "CheckButton" pos:[55,65] width:26 height:24 
 checkbutton ckb4 "CheckButton" pos:[25,126] width:83 height:23 
 
 function ckb_func inputState inputNodes =
 	(
 		if inputState then 
 		(selectmore inputNodes)
 		else (deselect inputNodes)	
 	);
 
 	on ckb2 changed state do
 	(
 	ckb_func state $dummy01;
 	)
  
 	on ckb3 changed state do
 	(
 	 ckb_func state $dummy02;
 	 )
  
 	on ckb4 changed state do
 	(
 	 if ckb4.state == true then
 		 (
 			ckb2.checked = true
 			ckb3.checked = true
 		 )
 	 else 
 		 (
 			ckb2.checked = false
 			ckb3.checked = false
 		 )
 		 
 	ckb_func ckb2.checked $dummy01;
 	ckb_func ckb3.checked $dummy02;
  
 	)
  
 )
  
 createdialog unnamedRollout