undo

The undo <boolean> context provides control over whether scripted scene changes will be undoable. By default, the operations performed in MAXScript are undoable. This means that scene-modifying commands typed in the Listener are undoable by default. Making this a context-controlled activity allows you to decide when the undo overhead is to be taken.

Example:

undo on

(

delete $box*

delete $sphere*

clearUndoBuffer()

)

The undoable operations appear as items labeled "MAXScript" in the 3ds max Undo menu. It is important to note that the granularity of the undoable operations is at the level of entire undo clauses. In the previous example, one entry is added to the Undo stack containing both deletes as a single operation. Choosing undo for this entry in the Undo menu causes both deletes to be undone. Therefore, you can control the granularity of an undo by choosing the appropriate undo block expression groupings.

You can invoke an undo from MAXScript with the max command:

max undo

When you script very large scene changes, you should consider turning undo off as it is quite easy to fill up the Undo stack and consume substantial amounts of memory. Disabling undo can improve performance in this situation. If the actions your script performs could interfere with entries already in the Undo stack, you should explicitly clear the Undo stack before enabling undo. An entry in the Undo stack generally expects the scene to be in the state it was when the entry was placed in the Undo stack. If you interrupt the storing of Undo stack entries, and modify the scene in an incompatible way (such as deleting an object that an entry assumes is still around), a 3ds max crash is likely if you then try to perform an undo.

Using the following functions you can control the undo and scene save states in 3ds max:

clearUndoBuffer()

empties the Undo stack, both providing a way to reset the undo state and another way to control the save-changes requester.

setSaveRequired <boolean>

lets you set the 3ds max system "dirty" flag. If this flag is set or there are entries in the Undo stack, you are asked if you want to save the scene file on a File > New or File > Reset.

getSaveRequired()

returns true if the 3ds max system "dirty" flag is set to true or if the Undo buffer is not empty. If the Undo buffer if not empty, this function will still return true, even if you just called setSaveRequired false.

Normally, if there are entries in the Undo stack when the scene is closed, 3ds max will prompt with a save-changes requester. In some cases, where you are controlling undo in MAXScript, you may want to force the need for a save-changes prompt.