MAXScript FAQ > How To Make It Faster > Disable Undo system when possible |
The undo system can consume large amounts of memory and slow down processing.
MAXScript commands run from Listener. Script Editor or Macro Script are run within an undo on context.
MAXScript commands run from scripted UI controls are not run within an undo on context.
Do not delete nodes with undo off, unless you also created the nodes with undo off and did not do anything to the node with undo on.
When working with meshes, you typically want to use meshop methods as they support undo/redo. But typically you do not want to store undo records for all operations in a loop, just the first and last.
When working with EPoly, you want to store undo records for all operations in a loop.
Every operation that creates an undo record will cost time and memory as it will create internal copies of the changing objects to allow an undo later. When making multiple changes in a loop like for example attaching multiple objects together, the Undo system would attempt to create a single undo copy of each resulting object and might even run out of memory. Disabling Undo explicitly using the Undo off () context can help to speed up scripts significantly in such cases.
The following extreme example shows the difference. In both cases, 1000 boxes will be created using MAXScript and then attached to a single mesh using the attach function. In the first case, each attach call will generate by default an undo record. In the second case, the undo will be explicitly disabled.
Disable Viewport Redraws when making changes to scene objects
Modify Panel can be slow -change to Create Panel when possible