Notifications
Clear all

[Closed] maxscript undo in an on changed handler

Hi guys,

I’m making a script that modifies transform in an on changed handler of a spinner control. My problem is if I put the undo clause in the on change handler, I get undo for each little increment of the spinner which is nearly always more than maximum undos (and a real bother to undo like 40 times to undo just one change.

Is there a way to start the undo group in the on button down handler and end it in the onbuttonup handler?

Thanks in advance,
Dragan

3 Replies
1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

you’ve already answered your own question…
here is an example which i showed on this forum:


try(destroydialog MovinZ) catch()
rollout MovinZ "Move In Z" width:200 height:50
(
   spinner move_sp "Move Value: " type:#worldunits range:[-1e9,1e9,0] fieldwidth:68 align:#center offset:[0,15]
   
   local moving_value = 0
   on move_sp buttondown do 
   (
      moving_value = 0
   )
   on move_sp changed val do
   (
      if not thehold.holding() do thehold.Begin()
      in coordsys local move selection [0,0, val - moving_value] 
      moving_value = val
   )
   on move_sp entered arg can do 
   (
      if thehold.holding() do
      (
         if can then thehold.Cancel() 
         else thehold.Accept "MovinZ"
      )
      move_sp.value = moving_value = 0
   )
)
createdialog MovinZ

Thanks man. It looks like it is the solution I was looking for. I was totally unaware of the thehold struct as an alternative to the “regular” maxscript undo clause which I haven’t been able to use in this case because it wouldnt allow it to begin in one handler and end in another as far as I can tell.

Thanks again for such a swift response:applause:

I tried it and it works like a charm. Thanks Denis