Notifications
Clear all

[Closed] dynamic checkbox state based on selection – stuck on this

Hi! I am trying to bring checkboxes for objects properties such as visibility to camera and and so on to my interface and stuck at updating checkbox state when selection changed and properties changed to.

I’ve tried “when select $ changes do ” construct but it doesn’t work with nothing selected and throw an error while <ChangeHandler:0x00000xxxxx> output instead of boolean value.

Is there any other way to make it work???

7 Replies
(
  	try(destroydialog Test) catch()
  	rollout Test "Test" width:150 height:130
  	(	
  		checkbox chk_collect "Check Box" checked:false pos:[10,10]
  		on chk_collect changed theState do
  		(	
  			if theState then
  			(	
  				print "I'm checked"
  			)
  			else
  			(
  				print "I'm not checked"
  			)	
  		)
  	)	
  	createdialog Test
  )	

a number of ways to handle this… but what I do is add a function to the rollout called
selectionChanged() which sets the rollout based on the current selection

then when the dialog/rollout is opened call
callbacks.addScript #selectionSetChanged myCallbackfn  id:myCallbackID
then on close
callbacks.removeScripts #selectionSetChanged   id:myCallbackID
then the call back fn would look something like this
fn myCallbackfn  =
    (	
    	  for ro in myWindow.rollouts.rollouts where ro.isDisplayed do
    		   ro.SelectionChanged();
)

or

fn myCallbackfn  =
 (	
    	  myWindow.SelectionChanged();
 )

depending how you handle the windows/rollouts

hope that makes sense, the selectionChanged function can also be used within the rollout as a default update ui proc within the rollout like
on myRollout open SelectionChanged();

for example

I wanted to post the same function, but I’m too late

this shows the general idea

(
	global theWindow;
	
	rollout theWindow "the Window"
	(
		fn selectionChanged selnodes =
		(	
			if selnodes.count > 0 then print selnodes[1].name;
		)
		on theWindow open do
		(
			callbacks.addScript #selectionSetChanged "theWindow.selectionChanged (selection as array)" id:#myCallbackID;
			selectionChanged (selection as array);
		)
		on theWindow close do
		(	
			callbacks.removeScripts #selectionSetChanged   id:#myCallbackID;
		)	
	)	
	
	try(DestroyDialog theWindow)catch();
	createdialog theWindow width:200 height:100 pos:[50,50] style:#(#style_toolwindow,#style_sysmenu)					  
)

THNX a lot! Callbacks exactly what I was looking for!

I had couples of issues with script flow and place of function in it but now it working !!!

Next will be to implement tristate:2 in case of different states in selection.

(
	global theWindow;
	
	rollout theWindow "the Window" width:136 height:48
	(
		
		checkbox VisibleToCamera "VisibleToCamera" pos:[16,16] width:108 height:16 checked:false
		
		fn selectionChanged =
		(	
			if selection.count > 0 then try (VisibleToCamera.checked = selection[1].primaryVisibility) catch print "Error" 
		)			
		
		on theWindow open do
		(
			callbacks.addScript #selectionSetChanged "theWindow.selectionChanged()" id:#myCallbackID;
			--selectionChanged();
			VisibleToCamera.checked = true
			print (VisibleToCamera.checked as string);
		)
		on theWindow close do
		(	
			callbacks.removeScripts #selectionSetChanged   id:#myCallbackID;
		)
	)
	
	try(DestroyDialog theWindow)catch(); -- close any windows of this type
	createdialog theWindow  pos:[50,50] style:#(#style_toolwindow,#style_sysmenu) 					  
)

instead of using General Events you can also use NodeEventCallback. it gives you a list of nodes (AnimHandles) which selection was changed.
another good thing of NodeEventCallback is it works in local scope.

I am grateful for direction Denis! Going to read help and will try to implement in this way later on.