Notifications
Clear all

[Closed] Detecting whether change handlers is triggered by undo/redo

Hello everybody!

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!

5 Replies

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.

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.

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.

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.
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.

sounds like a relatively clean solution to me – didn’t know you could still operate the meshes with control pressed