|
Mastering
3D Studio MAX R3 |
Global Properties
We can adjust several properties of a UI item. Properties are used to
organize UI elements in the script and to allow easier manipulation. We
can turn items on or off, or position and align any UI item.
An item can be enabled or disabled very simply. At creation time, specify
enabled:true or enabled:false. To change
this later in the script, just attach the .enabled property.
For instance, we can create a button that begins turned off, using:
button create “Button Example” enabled:false
Later in the script, if we want to enable this button we can use:
create.enabled = true
We can specify the position of each item using pos:[x,y].
Sometimes we might want one spinner beside another, and only changing
the position of the spinner in the UI will allow us to do it. An easier
way is using offset:[x,y], which will specify the position
based on the actual position of the object.
An easier way to specify the position of an item is aligning it to the
left, right, or center, using align:#left, align:#right,
or align:#center.
Other Interface
Items
There are many more interface items than spinners and buttons. Some will
be demonstrated in other chapters, but lets look at the most common
ones here.
Sliders
Sliders are similar to spinners, with a different UI. They work the same
way, except they can be horizontal or vertical. Sliders do not allow us
to specify the stepping using the scale property.
Lets change the spinner from the example we used before to a slider.
Edit the spinner line, changing the word spinner to slider
and removing the scale definition, this way:
slider bend_ang “Angle” range:[-180,180,0] type:#float
Evaluate the script and play with the slider, as in Figure 15.3.
FIGURE
15.3 The Utility Example script, with a slider
We can make the slider horizontal (default) or vertical, using the orient
property: orient:#vertical or orient:#horizontal.
We can also add a series of ticks to indicate the stepping of the slider,
specifying ticks:number, where number is the number of
ticks to be added. For instance, lets change the slider to vertical
and add five ticks to it:
slider bend_ang “Angle” range:[-180,180,0] type:#float \
orient:#vertical ticks:5
Evaluate and see the difference. (Remember that lines that end with a
backslash are continued in the next line.)
|
|
| TIP Use sliders
where no precision is needed. Its not possible to adjust a value
the same way as with spinners, and its also not possible to
reset a slider as we can by right-clicking a spinner.
|
Check Box
A check box is an ON/OFF control. Its useful for many actions in
MAXScript. All the options in the Object Properties dialog box are check
boxes. Another example can be seen in Figure 15.4
FIGURE
15.4 A sample check box
Check boxes can be used to control many options within objects. Lets
write a script that will add a default material to an object, and will
allow us to specify whether the object is or is not transparent. Start
a new script and type:
utility glass “Glass Material”
(
button go “Assign Material” tooltip:“Assign Material to Selected” width:120
spinner opac “Opacity” range:[0,100,50] type:#float
checkbox onoff “Transparent” checked:true
on go pressed do
(
if selection.count == 0 then format “Select an object first.\n”
else
(
mat = standardmaterial()
if onoff.checked == true then
mat.opacity = opac.value
else
mat.opacity = 100
$.material = mat
)
)
on opac changed val do
(
if mat != undefined then
if onoff.checked == true then
mat.opacity = opac.value
else
mat.opacity = 100
)
on onoff changed state do
(
opac.enabled = state
if mat != undefined then
if onoff.checked == true then
mat.opacity = opac.value
else
mat.opacity = 100
)
)
This script allows the user to select an object and assign a default
Standard material to it. Then, it checks to see if the onoff check box
is turned on, using the checked property. If its
on, the sliders opacity will be used; if its off, the object
will not be transparent, and the slider will be disabled.
When adjusting the properties of the spinner and the check box, we first
need to check whether the material was created and assigned. This is done
using if mat != undefined. The script will only change
the transparency of the material that has just been assigned to the object.
You will learn later how to adjust properties on selected objects, and
how to ask the user to select objects.
This script would be a great place to use functions. If we defined
several commands into a function here, we would save a lot of code, since
if onoff.checked is called three times in the script. Well
use functions in future examples so you can see the difference.
Colorpicker
The colorpicker is a UI item that allows us to choose one color. It displays
the Color Selector dialog box and returns the selected color value. Lets
add it to our example script, as in Figure 15.5, and lets adjust
some values.
FIGURE
15.5 A sample colorpicker
You can find the final script on the CD as utility_transparency.ms.
Between button and spinner, add:
colorpicker mat_col “Material Color” color:[255,255,255]
This will create the colorpicker and set its default color to white.
Now lets add the events that will change the color of the object
in the scene. Below checkbox, add the following code:
on mat_col changed val do
(
if mat != undefined then
(
mat.diffusecolor = mat_col.color
mat.filtercolor = mat_col.color/2
mat.ambientcolor = mat_col.color/4
)
)
In addition, we need to edit on go pressed, so it reads
the colorpicker color and uses it in the material. After mat =
standardmaterial() add:
mat.diffusecolor = mat_col.color
mat.filtercolor = mat_col.color/2
mat.ambientcolor = mat_col.color/4
The changes we made will set the ambient, diffuse, and filter color;
all three are based on the colorpicker color we created. Evaluate the
final script and test it on any object you wish. Notice that the color
adjusted through the Color Selector dialog is interactive and displayed
on screen.
As an exercise, create a separate colorpicker for each color, create
different spinners, and adjust the script as you wish.
Pickbutton
The pickbutton is a button that will be used to select an object. Its
similar to the Pick Operand button in ShapeMerge, Conform, Boolean, etc.
Lets edit the script we just wrote and add a pickbutton, to select
the object before assigning the material, as in Figure 15.6:
FIGURE
15.6 A sample pickbutton
© 2000, Frol (selection,
edition, publication)
|