Change Handler Runtime Error

Change Handler Runtime Error

Anonymous
Not applicable
553 Views
3 Replies
Message 1 of 4

Change Handler Runtime Error

Anonymous
Not applicable
Hi again everybody!

I'm having some trouble with a change handler. When I run a piece of code that executes the handler:

-- there's a rollout defined up here


on createCntrl close do
(
unregisterRedrawViewsCallback enableCheck
deleteAllChangeHandlers id:#controlOtron
global enabledCheck = undefined
) -- I did this to try and make the callback/handler stop when I close the window.
-- Does nothing as far as I can tell.

) -- end rollout

createDialog createCntrl 200 200

global enabledCheck -- declaring the fn as a global like it says in the help file
unregisterRedrawViewsCallback enableCheck
fn enabledCheck = print "poop"

registerRedrawViewsCallback enabledCheck
deleteAllChangeHandlers id:#controlOtron

when select selection changes id:#controlOtron handleAt:#redrawViews do enabledCheck()
) -- end of script


What happens when I execute the code is this:

-- Runtime error: group selection: selection empty

Which is a problem because I expect the code to be executed often when there is no selection.

Secondly, I can't get the callback or handler to stop. It just keeps printing:

"poop"

to the Listener. Even more confusing to me is that it prints whenever the viewport redraws instead of just when the selection changes.

I tried to set it like like it shows in the help file: How To ... Enhance the Morpher Modifier With Floating Controls

Thanks again for any tips. The help files are just so dang vague. It makes it really hard to get things to work right >:|
0 Likes
554 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
why not just put an "if selection.count>0 do" before the when construct?
0 Likes
Message 3 of 4

Anonymous
Not applicable
Ha, good idea. I never even thought of that. All the examples show the "when" isolated like that so I just assumed that was the way they had to be constructed. I'll give it a shot. Thanks.
0 Likes
Message 4 of 4

Anonymous
Not applicable
Ok, I think I got this. I found another help file with a callback example:

How To ... Develop a Selected Objects Inspector using ListView ActiveX Control - Part Two

So I modified mine to work like the example:

-- script body up here

fn enabledCheck = print "poop"

on createCntrl close do callbacks.removeScripts #selectionSetChanged id:#controlOtron

) -- end rollout

try(destroyDialog createCntrl)catch()
createDialog createCntrl 200 200
callbacks.addScript #selectionSetChanged "createCntrl.enabledCheck()" id:#controlOtron

) -- end script


So it looks like this way will add the callback script and then remove it when I close the window so it doesn't keep running in the background.

I think maybe that "when" construct I was using is better for tools that need constant updates with scene redraws. I'll have to keep studying it.
0 Likes