Page 1221 - Kitab3DsMax
P. 1221
Chapter 49: Automating with MAXScript
Scripted utilities
A scripted utility is a MAXScript that has its own custom rollout in the Utilities panel, like the SphereArray exam-
ple. This type of script is particularly useful when your script has parameters that the user needs to enter, such
as the radius in the SphereArray script. Scripted utilities are easy to build using the Visual MAXScript Editor.
Scripted right-click menus
When you right-click an object in your scene, Max opens a pop-up menu of options for you to choose
from, much like a quadmenu. Scripted right-click menus let you append your own menu items to the right-
click menu. If you create a script that modifies some property of an object, making the script available
through the right-click menu makes it easily accessible.
Scripted mouse tools
You can use scripted mouse tools to create scripts that handle mouse input in the viewports. These scripts
listen for commands from the mouse, such as clicking the mouse buttons and clicking and dragging the
cursor. For example, you would use this type of MAXScript if you were making a new primitive object type
so that users could create the new objects just like they would a sphere or a box.
Scripted plug-ins
Scripted plug-ins are by far the most complex type of MAXScript available. They mirror the functionality of
non-MAXScript plug-ins (which are written in other programming languages such as C++). You can create
scripted plug-ins that make new geometry, create new shapes, control lights, act as modifiers, control tex-
ture maps and materials, and even produce special rendering effects.
Writing Your Own MAXScripts
This section presents the basics of the MAXScript language and shows you how to use the various parts
of MAXScript in your own scripts. You can test any of these scripting commands using the MAXScript
Listener window.
Cross-Ref
Much of the discussion that follows will sound familiar if you’ve already read the material on expressions found in
Chapter 35, “Animating with the Expression Controller and Wiring Parameters.” Expressions use many of the same
constructs as MAXScript. n
Variables and data types
A variable in MAXScript is sort of like a variable in algebra. It represents some other value, and when you
mention a variable in an equation, you’re actually talking about the value that the variable holds. You can
think of variables in MAXScript as containers that you can put stuff into and take it out of later. Unlike vari-
ables in algebra, however, variables in MAXScript can “hold” other things besides numbers, as you’ll soon see.
To put a value into a variable, you use the equal sign. For example, if you type
X = 5 * 3
in the MAXScript Listener window, Max evaluates the expression on the right side of the equal sign and
stores the result in the variable named X. In this case, Max would multiply 5 and 3 and would store the
1173