Tween Machine - PySide6

65 views
Skip to first unread message

Shaikh Anas

unread,
Oct 20, 2024, 6:11:35 AMOct 20
to Python Programming for Autodesk Maya
Hello everyone, I am creating a tween machine just for my educational purpose and to understand the logic of it.

I am facing multiple undo issues.

I am attaching two images, where the function is the same, the difference is one, I am running independently to check if is it working fine and 2nd is running through a signal.

So the issue is when a single calls this function it runs perfectly but If I want to undo the changes it will undo every single attribute one by one which takes lots of undo to change.

If I run the script indecently ( screenshot_3.png ) and undo that, it simply takes one undo to change the entire action.

Thanks and Regards,
Shaikh Mohammad Anas


Screenshot_4.png
Screenshot_3.png

Marcus Ottosson

unread,
Oct 20, 2024, 10:52:16 AMOct 20
to python_in...@googlegroups.com
Try calling these before and after the function.
cmds.undoInfo(chunkName="myFunction", openChunk=True)
my_function()
cmds.undoInfo(chunkName="myFunction", closeChunk=True)
This will cause all undoable calls to maya.cmds to be grouped together into a "chunk". It's important to call closeChunk after, as it could otherwise make Maya and undoing unstable. To make it more safe, you could use something like a context manager.
@contextlib.contextmanager
def undo_chunk(name):
    try:
        cmds.undoInfo(chunkName=name, openChunk=True)
        yield
    finally:
        cmds.undoInfo(chunkName=name, closeChunk=True)

with undo_chunk("myFunction"):
   my_function()
That way, even if your function fails or throws an exception, the chunk will still be closed.


--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/82d3cfa9-1d1f-4eb9-b372-ac7ba89b8bbfn%40googlegroups.com.

Shaikh Anas

unread,
Oct 20, 2024, 12:54:41 PMOct 20
to Python Programming for Autodesk Maya
Thank you so much, Marcus

It's working excellently and I appreciate your time too.
I have been following you for very long :)

Thanks again!

Marcus Ottosson

unread,
Oct 21, 2024, 3:58:55 AMOct 21
to python_in...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages