View Full Version : Detecting whether change handlers is triggered by undo/redo
02-08-2009, 03:27 PM
I'm using a "when geometry myNode changes" construct to detect when the user moves vertices.
However, the change handler also gets called when doing undo/redo.
Is there a way to avoid this?
Thanks a lot!
02-08-2009, 07:53 PM
Hmm... the only thing I can think of is performing your code in a delayed fashion.
I.e. in your when handler, start a small timer that triggers after - I dunno - 100ms. IF within those 100ms the #sceneUndo / #sceneRedo system callback is triggered, stop your code from doing anything, otherwise carry on.
Sounds iffy, I know, but looks like there's no 'sceneUndoBegin' that triggers -before- the change and 'sceneUndoEnd' afterwards that would make what you'd need easypeasy.
02-09-2009, 08:42 AM
Thanks for the reply!
I tried what you suggested, but it didn't work:
local iTime1 = timeStamp()
local iTime2 = timeStamp()
while iTime2-iTime1 < 100 do
iTime2 = timeStamp()
I also tried using sleep() with the same result:
Even with this delay the sceneUndo callback script is executed after the change handler.
So I'm afraid this is not possible.
02-09-2009, 10:22 AM
ouch.. wrong type of timer ;)
That code will essentially halt all 3ds Max operations until your loop is done; a synchronous timer. You'll want an asynchronous timer - use either a rollout with a timer control in it, or create a .NET timer (see topic 'How To … Call a MAXScript Function Periodically using DotNet' in help file).
No guarantee that -that- will work flawlessly, though.. like I said, it's pretty iffy.. say an undo takes 200ms to complete and the timer triggers and injects itself in the middle of that undo.. I'm hoping that doesn't happen and max queues the command until after the undo is finished.
02-09-2009, 04:30 PM
Oh, I didn't know about those. Thanks! :)
However, as you said this solution is 'iffy', especially because it would delay any normal operation aswell.
So I chose another dirty solution: the change handler only executes when keyboard.controlpressed is false. :P
It's so dirty that I don't want my mom to know about it, but it's fast and works for most people, hopefully. :)
02-09-2009, 05:00 PM
sounds like a relatively clean solution to me - didn't know you could still operate the meshes with control pressed :)
02-09-2009, 05:00 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.
vBulletin v3.0.5, Copyright ©2000-2015, Jelsoft Enterprises Ltd.