Main toolbar > Open Track View > Select a track in the Track View Hierarchy > Track View toolbar > Assign Controller > Script
Graph Editors > Track View > Open Track View > Select a track in the Track View Hierarchy > Track View toolbar > Assign Controller > Script
Six Script controllers are available in the software:
Float Script - float controller
Position Script - position Point3 controller
Point3 Script - Point3 controller
Rotation Script - rotation Quaternion controller
Scale Script - scale Point3 controller
Transform Script û matrix3 PRS controller
The Script controllers work similarly to Expression controllers. They provide a Properties dialog where a script can be entered for computing the controller value. The primary advantages of Script controllers are:
They can use all the features of the MAXScript language, including loops, scripted functions, pathnames, and so on.
Almost any property of any object in a scene can be used to help compute controller values, including mesh vertices, values of properties at arbitrary frame times, and other non-animatable properties that are not accessible in Expression controllers.
They can use MAXScript global variables to communicate and coordinate with other controllers and scripts in the software.
The software interprets the text you type into the Script text box as the body of a MAXScript block expression. You can type as many expressions as you want on as many lines as you want, and they are evaluated in turn. The value of the last expression is taken as the controller value. This value must yield the right type for the controller: Float for float, Point3 for position, Quat for rotation, and so on.
Since the text is inside a block expression, you can declare local variables that are visible only within the script and are temporary for one evaluation. You can also declare or access global variables that are shared with all other scripts in MAXScript and hold their values from one evaluation to the next.
A controller is always evaluated by the software with respect to a specific animation time. This might be the current time slider or incrementing frame time if an animation is playing. In the case of Script controllers, the time being evaluated is used to establish an automatic "at time" context around the controller script, so any properties you access (outside of other explicit ôat timeö expressions) yield the correct values for the current controller evaluation time. This means you don't have to do anything special in your scripts to work at the correct time. You can access the evaluation time, with the standard MAXScript variable, current Time. You can also reference scene property values at other times by using "at time" expressions in your scripts, as in regular MAXScript programming.
See also
Procedure
Example: To keep an object centered relative to other objects in the scene during an animation:
Assign a Script controller to the Position track of the object that should remain centered.
Right-click the Position track in the Track View Hierarchy and select Properties.
Type the following script in the Script Controller dialog window.
local pos=[0,0,0]
for o in objects where o != $foo do
pos += o.pos
pos / (objects.count - 1)
This script computes the average position of all objects, except the current one (written as $foo here) by setting up a local, iterating over all objects except $foo, accumulating a total position vector, and computing the average in the last line, which is the final result of the script.
Interface
After assigning a Script controller, a Properties dialog is available by right-clicking the track in the Track View Hierarchy and selecting properties or clicking the Properties button on the Track View toolbar.
Script Controller dialog
Script: Type the script to compute the controller value here.
Result: Shows the results of an evaluation or any error messages caused by errors in your script.
Evaluate: Evaluates the controller script and prints the result in the Result box. The evaluation is computed for the current position of the time slider.
Close: Compiles and checks the controller script. If everything works, the Properties dialog is closed. Any problems result in a query box asking whether you really want to close the box with an incorrect script. If you do, the controller will yield a null value (0, [0,0,0],) when evaluated.