Undo group problem

   220   0   0
User Avatar
Member
689 posts
Joined: Nov. 2013
Offline
In the shelf tool, throwing an exception does not modify the scene. I want to implement this functionality in the Python panel.
This code works normally.

try:
    with hou.undos.group("my code"):
        hou.node('/obj/geo1').createNode('box')
        hou.node('/obj/geo1').createNode('box')
        raise hou.Error()
except:
        hou.undos.performUndo()


However, if an error occurs before modifying the scene, the current undo group is not recorded in the undo history. The undo executed in the except block will cancel the previous operation.

try:
    with hou.undos.group("my code"):
        raise hou.Error() # raise exception before modifying scene , no undo is added to undo history.
        hou.node('/obj/geo1').createNode('box')
        hou.node('/obj/geo1').createNode('box')
                
except:
        hou.undos.performUndo() # undo operation before my code

How to solve this problem?

Thanks!
  • Quick Links