Undoing and Redoing Custom Commands

 
 
 

When you need to undo/redo actions performed by a C++ API custom command on non-scene data, you can implement it in the Undo, and Redo callbacks.

Important

The custom command is only responsible for undoing the work performed on the user data only: Softimage could become unstable if scene data are modified during undo or redo (for example, calling undoable commands). For instance, if the custom command fires a series of SetValue commands, the Undo callback shouldn't undo these actions on its own, this is taken care of by Softimage automatically.

No matter when the user data is modified during the execution of an undoable command, the custom Undo callback is always executed once all Softimage commands are undone and the Redo callback is always called before any Softimage commands are redone.

Implementating Undo and Redo

In the command's Execute callback, you can check the TermUndoRedo context attribute to see whether you have to allocate memory for undoing and redoing the command action. If so, you store the command action data by setting the UndoRedoData attribute. This data can then be used by the Undo and Redo callbacks to reverse or redo the work done in the command's Execute callback. The data must be released in TermUndoRedo.

For more control, the undo data management can be handled entirely by the plug-in. In which case the custom command will have to maintain its own undo stack in order to match with Softimage's undo stack.

Tip

The Simple Undoable Command example demonstrates how to implement an undoable custom command with the C++ API. The example creates a NetView view at 0,100 and the undoable command moves the window to 200,100. The positioning of the window can be undone and redone through the Undo and Redo Softimage built-in commands.

Creative Commons License Except where otherwise noted, this work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License