def no_undo(): """Disable undo during the context""" try: cmds.undoInfo(stateWithoutFlush=False) yield finally: cmds.undoInfo(stateWithoutFlush=True)