View Full Version : Change handlers for modifier enbled states?
04 April 2008, 08:29 AM
I'm looking for a way to execute a function that will update a floater when things are changed in a modifier, especially (at the moment) when the modifier is turned off,on or off inviews etc.
I've found the "when parameters $ changes" and that works perfectly if I have an object selected when I open the dialog that sets the "when parameters". But if I have nothing selected, I get a rollout handler exception:
-- Runtime error:Change Handler setup requires Max Object or Max object collection, got:undefined.
Does anyone have a way of doing this? I tried the #modPanelObjPostChange callback but that doesn't seem to work with the modifier.enabled states.
04 April 2008, 09:55 AM
well, pretty much as the error message states, change handlers can only be set up for given objects. So your script should check if there are objects selected - if there aren't, it should not set up the change handler.
You can use a selection change callback to keep track of whether objects get selected and delete your existing change handler and create a new one for the new selection when the selection does change.
04 April 2008, 10:35 AM
scary code incoming
fn createChangeHandler = (
local sel = getCurrentSelection()
if (sel.count > 0) then (
when parameters sel changes id:#test handleAt:#redrawViews obj do (
if (obj.modifiers.count > 0) then (
format "-- modifier states for object '%':\n" obj.name
for i = 1 to obj.modifiers.count do (
m = obj.modifiers[i]
format "%) %.enabled: %\n" i m.name m.enabled
format "%) %.enabledInViews: %\n" i m.name m.enabledInViews
format "%) %.enabledInRenders: %\n" i m.name m.enabledInRenders
rollout test "test" (
on test open do (
callbacks.addScript #selectionSetChanged "createChangeHandler()" id:#test
on test close do (
The rollout sets up the callback and calls the change handler function on opening and deals with removing it, and the change handler, when it closes.
The callback calls the function that creates the change handler whenever the selection changes.
The change handler setup function first removes the change handler, then checks if there is a selection (if not, it ignores). If there is a selection, it sets up a new change handler for the current selection.
That change handler's code checks if the object has modifiers (if not, it ignores). If there are indeed modifiers, it proceeds to print out the object's name, and then each modifier's enabled states. The modifier name is preceeded by an index number - this is the modifier index as listed top-down in maxscript's funky modifier access ($.modifiers isn't the first modifier applied to the object, it's the top-most modifier in the modifier stack.)
I hope that explains the code a bit :)
04 April 2008, 12:30 PM
AH, yes. Very clever. Thanks for that. I've only just started using callbacks and change handlers. That's just opened a whole world of options by thinking that way.
Is there much of a slowdown with callbacks and event handlers? Should I be trying to limit the use of them?
04 April 2008, 02:18 PM
there's some slowdown - you'll always want to limit their use as much as possible and make the functions within as efficient as possible. The most important thing to keep in mind is to remove callbacks / change handlers when you're no longer going to use them. Not just for efficiency reasons, but because if you add a new callback / change handler for the same thing, the event will end up getting triggered twice. In general, any time you create a callback / change handler for a given element, you should remove the existing one first.
04 April 2008, 02:18 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.