GENERATE/PREV.gifGENERATE/NEXT.gif

Context Expressions

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

The basic idea is that 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 UI and moved some 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.

Here is the full syntax for <context_expr>:

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

where <context> is one of:

[ with ] animate <boolean_expr>

with redraw <boolean_expr>

at level <operand>

in <operand>

at time <operand>

[ in ] coordys <coordsys_spec>

about <center_spec>

undo <boolean_expr>

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 contexts effect code as follows:

animate: if on causes keyframes to be generated whenever an animatable property of a MAX object is changed. It works identically to the animate button in the user interface. Default is off.

at level or in: takes a <node> operand and sets it to be the current parent for any scene object creation, so that new objects are automatically made children of that <node> and makes it the effective root for any pathnames. Default is no parent.

at time: sets the current working time. Any animatable property references will yield their interpolated values for that time. Default is the current time slider position.

The following are Context expressions:

coordsys

about

undo

See also:

Cascading Contexts

Nested Contexts

Sticky Contexts