Context Expressions

Context expressions are parts of the MAXScript syntax that are 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 that is supplied to set up a context for the evaluation of its expression.

FOR EXAMPLE,

b1 = box()
b2 = box()
animate on
(
  move $box001 [20, 0, 0]
  rotate $box002 45 x_axis
)

This effectively "turns on" the animate button for the duration of its block-expression. The move and rotate automatically generate keyframes, just as it happens when you turn the animate button on in the 3ds Max user interface and move 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, you can see how to do keyframe animation in MAXScript.

FOR EXAMPLE,

animate on
(
  at time 0 $box001.position = [-100, 0, 0]
  at time 100 $box001.position = [100, 0, 0]
)

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>
[ with ] redraw <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 $box001 rotate $box002* 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
      $box001.pos = $box002.pos + random [-10,-10,-10] [10,10,10]

The individual context expressions are described in the following topics:

animate

at level, in

at time

coordsys

about

undo

redraw

See Also