Context Expressions

Context expressions are the parts of the MAXScript syntax that are most specifically designed for use with 3ds max. Context expressions are mirrors of some of the most important abstractions in the 3ds max user interface - the animate button, the time-line slider, the working coordinate system, and so on. Context expressions make it as easy to create animation and perform geometry manipulation in MAXScript as these tools do in the user interface.

The basic idea for this is a prefix is supplied that sets up a context for the evaluation of its expression. For example:

animate on

(

move $box01 [20, 0, 0]

rotate $box02 45 x_axis

)

This effectively "turns on" the animate button for the duration of its block-expression. The move and rotate will automatically generate keyframes, just as would happen if you turned the animate button on in the 3ds max user interface and moved objects around. Another kind of context expression has a prefix for setting the current animation time, as though you had moved the time slider. If we mix the two forms together, like this:

animate on

(

at time 0 $box01.position = [-100, 0, 0]

at time 100 $box01.position = [100, 0, 0]

)

you can see how to do keyframe animation in MAXScript.

The full syntax for <context_expr> is:

<context> { , <context> } <expr>

where <context> is one of:

[ with ] animate <boolean>

at level <node>

in <node>

at time <time>

[ in ] coordsys <coordsys>

about <center_spec>

[ with ] undo <boolean>

Examples:

-- randomly jiggle each object in the selection around + or - 20 units

in coordsys local selection.pos = random [-20,20,20] [20,20,20]

-- rotate all the boxes 30 degrees about the y_axis of $foo

about $foo rotate $box* 30 y_axis

-- generate a keyframed animation of $foo randomly chasing $baz

animate on

for t in 0 to 100 by 5 do

at time t

foo.pos = $baz.pos + random [-10,-10,-10] [10,10,10]

The individual context expressions are described in the following topics:

See also