GENERATE/PREV.gifGENERATE/NEXT.gif

Sticky Contexts

You can force the settings of contexts such as coordsys, animate, time, etc., to be "sticky" so they stay active for any code execution that follows, up until the point you change them or override them with a context prefix for some 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 having to prefix 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, redraw, in, coordsys, about, level or undo.

Example:

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 <time_value> | off      -- variant of at time <t>

set level <scene_node>      -- variant of at level <o>

The time context can be set to off, signifying that the current value of the 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 the 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

When using the set undo on construct to enable the undoing of scripted changes in the Listener, undo granularity is at the level of top-level expressions - every time you evaluate an expression or sequence of selectected expressions with the ENTER or <numpad-enter> key, a single entry is added to the undo stack.