App.undoSuspend

From The Foundry MODO SDK wiki
Jump to: navigation, search

app.undoSuspend is a special command to used to help reduce the memory usage of a script.

The Problem

Many scripts build or otherwise manipulate geometry, which requires executing commands. Any command that modifies the scene state is undoable. These undos can eat up quite a lot of memory. Particularly complex operations can result in all of the memory in the system being used, causing the OS to hit the disk for virtual memory and bring the system to a crawl.

A Solution

To work around this issue, a script can tell modo to discard all undos immediately after any command is executed by calling app.undoSuspend. Commands will execute and add undos as normal, but as soon as the command finishes it discards any undos created. This state is only live while the parent command (as in, the script itself) is running, and automatically resets once the script finishes executing.

Since this command discards undos, it also results in the entire undo stack being cleared. This is necessary as undos must be a single unbroken change, and app.undoSuspend breaks the chain. You should be aware of this before using it in your script, as it may significantly affect a user's workflow.

app.undoSuspend is admittedly not an ideal solution to this problem, but it is currently the best option available within the limits of how the command system and system functions.

More Information