Sticky Contexts

You can force the settings of contexts such as coordsys, animate, time, and so on, to be "sticky." The settings will stay active for any code execution that follows, up until the point you change them or override them with a context prefix for an expression. This is particularly useful when working in the Listener, allowing you to set a context and then perform several interactive operations in that context without prefixing each with the desired context construct.

Establishing a sticky context is accomplished with the set construct:

set <context>

where <context> is one of the MAXScript context prefixes: animate, time, in, coordsys, about, level, or undo.


set animate on

set time 30f

move $foo [80,0,0]

scale $baz [1,1,3]

$bar.bend.angle += 23


set animate off

set time off

This turns animate on and sets the current time to frame 30 after which any number of interactive operations can be performed that will generate animation at frame 30. The modes are then returned to default. As shown in this example, certain the MAXScript contexts permit syntactic variants to make the set construct read clearly. In particular, these are:

set time <value> | off -- variant of at time <time>

set level <node> -- variant of at level <node>

The time context can be set to off, signifying the current value of the 3ds Max time slider is to be used.

All the set constructs are expressions that yield the context setting that was in force at the time the new context was set. This allows you to simulate the standard nested forms of these constructs by storing the old context in a variable and using that to restore the context later.

For example:

oc = set coordsys parent -- remember old coordsys

rotate $foo (quat 30 z_axis)


set coordsys oc -- restore it

You can also force several of the contexts back to their default states by specifying #default as their parameter. The set constructs for which you can specify #default are: animate, in, coordsys, and level.

When using the set undo on construct to enable the undoing of scripted changes in the Listener, undo granularity is a top-level expression. Every time you evaluate an expression or sequence of selected expressions with the ENTER or Number-Pad ENTER key, a single entry is added to the Undo stack.