You’ve got the right idea, but I’m not sure what you expect is what your
users would expect? Am I understanding it correctly that a user would:

   1. Open your UI
   2. Click a button
   3. Think for a moment..
   4. Click another button
   5. Check their phone..
   6. Click a third button
   7. Close the UI

And then when they hit Ctrl + Z it would undo each of these 3 button
presses? If it was me, I would expect 3 clicks to require 3 undos.

If you really did want to undo each of the three items, then you’re on a
bit of thin ice but not impossibly thin. You can:

   1. On window open, open that undo chunk
   2. Let the user click buttons
   3. On window close, close the undo chunk

That way, the next undo would undo all of it. The reason it’s thin ice is
because the undo chunk is global to Maya and would include anything they do
outside of it also. So the next undo may take other things with it that
falls outside of your control.

Generally, undo has a temperament and should be dealt with cautiously. It
can easily break other undo’s in the queue and often bring Maya down with
it. So if you can, I would recommend you do what Maya does naturally and
avoid undoInfo.

On Fri, 23 Sept 2022 at 10:59, Pacifique Nzitonda <
nzitondapacifi...@gmail.com> wrote:

> I have a question about PySide2 undo/redo in Maya. I read a discussions
> about using undoInfo Maya command but what if my GUI has to interact with
> many methods? How can I create an undo/redo for all of them at once instead
> of doing:
>
> def method1():
>     cmds.undoInfo(openChunk=True)
>     # my code
>     #
>     cmds.undoInfo(closeChunk=True)
>
> # or even
> def method2():
>     try
>         cmds.undoInfo(openChunk=True)
>         # my code
>         #
>     except:
>         pass
>     finally:
>         cmds.undoInfo(closeChunk=True)
>
> def method3():
>     cmds.undoInfo(openChunk=True)
>     # my code
>     #
>     cmds.undoInfo(closeChunk=True)
>
>
> I want this:
>
> cmds.undoInfo(openChunk=True)
> def method1()
> def method2()
> def method3()
> cmds.undoInfo(closeChunk=True)
>
> Knowing that each method is connected to a button on the GUI
>
> --
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to python_inside_maya+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/15e4aa30-72d1-4122-b1ee-d40b9c63d068n%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/15e4aa30-72d1-4122-b1ee-d40b9c63d068n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to python_inside_maya+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOCJeLC2uOb%3DtnO9j4SciUFar_RmcHvyK3QOGMwG17ioYQ%40mail.gmail.com.

Reply via email to