|
|
Mastering
3D Studio MAX R3 |
|
| WARNING Many plug-ins are
available for MAX R3. Some of them are macro-recordable, and others
are not, depending on how the developer created the plug-in code.
Its a good idea to ask the developer about recordability and
to request MAXScript capabilities in plug-ins.
|
Working with Variables
Variables are simply containers that hold a value, property, etc. Why
do you need variables? To make scripting fluid and customizable. For instance,
you can make a script to find out whether the current temperature is hot
or cold. This script would compare the current temperature with a certain
value. If the current temperature is below, say, 30, it is cold. Doing
this as a script, you would have a variable, called temperature, which
you would compare to another variable, named cold, and this comparison
would tell you if it is cold or not. Using this method, you can easily
change the values of either variables and re-run the script over and over.
Variables are also useful because they allow you to know what property
you are using, which is convenient when you are working with the name
of the property, not the property itself. Suppose you need to access a
property in a diffuse map of an object. To do it in MAXScript, you would
need to use object.material.diffusemap .property. If you
assign a variable = object.material.diffusemap, you will
save time using just variable.property in the future.
|
| NOTE In MAXScript, the equal
sign (=) acts as a command; it tells MAX to make the item on the left
equal to the item(s) on the right. To find out whether two
things are equal, we use a double equal sign (==), which is described
in Comparing Variables below.
|
If you compare MAXScript to other programming languages, it is very easy
to assign variables in MAXScript. Almost every programming language requires
you to declare variables, variable types, even the amount of memory to
be used. In MAX-Script, you dont need to do anything like this.
Assigning
Variables
Assigning variables is simply done by entering a value for the variable.
And you can use any kind of valuea number, a property, a string
of text, etc.
You can use any name for a variable, excluding some names used by MAXScript
commands, special characters, and spaces. A variable name can also have
numbers, but it must start with a letter. Here are some of the most common
types of variables you can assign in MAXScript.
| Variable
| Description
| Example
|
| Integer
| Integer number
| x = 1
|
| Float
| Decimal number
| x = 1.2345
|
| String
| Any text
| x = celsius
|
| Point2
| Any X, Y position
| x = [12,-25]
|
| Point3
| Any X, Y, Z position, color, etc.
| x = [12,-25,8]
|
| Time
| Time, in MAX formats (frames, SMTPE, seconds)
| x = 3m18s7f (min, sec, frames)
|
| Array
| Array of variables
| x = #(8,text,5f)
|
You can assign an integer value to a variable, and later in the script
you can assign a different value, which doesnt need to be an integer.
This is different from many programming languages, where you cant
automatically change a variable type once its assigned. Very few
operations can be done mixing variable types.
Now you will assign some variables so you can see how its done
in MAXScript:
- 1. Open the Listener.
- 2. Type x = 1 and press Shift+Enter.
|
| NOTE Pressing
Shift+Enter processes the line and displays the result on
the subsequent line in the output/command pane. (Pressing Enter
alone moves the cursor to the next line, but only processes the
command if the cursor is in the last line.) The number pad Enter
key processes the line the same way as Shift+Enter. This process
step is called evaluate, and well refer to it this way in
the book.
|
- 3. Type y = 2.5 and evaluate.
- 4. If you type x and evaluate, MAXScript
will display the value of the x variable.
Performing Math Operations
Math operations are performed the same way variables are assigned, simply
by typing the math formula, for example, z = x + y.
All math rules are respected in MAXScript, which means that you can use
parentheses and the precedence rules. That is, data in parentheses will
be evaluated first, then exponential operations, then multiply and divide,
and finally, addition and subtraction. Suppose you have the two following
examples: 2 * 3 + 4 and 2 * (3 + 4). In the first instance, MAXScript
will first calculate 2*3 and then add 4. In the second one, MAXScript
will first calculate 3+4 and then multiply the result by 2.
Performing
Basic Math Operations
Lets work with some variables and basic math operations to get
a feel for how MAX handles these functions.
© 2000, Frol (selection,
edition, publication)
|
|