Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
3ds Max 6 Bible (2004).pdf
Скачиваний:
55
Добавлен:
17.08.2013
Размер:
50.02 Mб
Скачать

Chapter 48 Automating with MAXScript 1145

Learning the Visual MAXScript Editor Interface

Building scripts can be complicated, and piecing together a rollout for a scripted utility can be especially time-consuming and frustrating when done by hand. To help create such custom rollouts, Max includes the Visual MAXScript Editor. Using this editor, you can drag and drop rollout elements and automatically create a code skeleton for certain events.

Working with textual commands can be time-consuming. In order for the script to work, you need to enter the commands exactly. This can be especially tricky when you’re trying to lay out the controls for a rollout. Max includes a tool called the Visual MAXScript Editor that speeds up the creation of rollouts.

To access the Visual MAXScript window, shown in Figure 48-14, open the Utility panel in the Command Panel and click the More button. Then select the Visual MAXScript option from the list of utilities, and click OK. Another way to access this window is to select Edit New Rollout or Edit Rollout (F2) in the MAXScript editor window.

Figure 48-14: The Visual MAXScript window makes building rollouts easy.

Layouts for a rollout created in the Visual MAXScript window can be saved as files with the

.VMS extension using the File menu. If you access the window from a MAXScript editor window, then the Save menu automatically updates the editor window.

The Editor interface

The window includes two major panes. The left pane is where the various rollout elements are assembled, and the right pane holds the Value and Event Handlers tabbed panels. The Value panel lists all the properties and their associated values for the selected element. You can change the property values by clicking on them and entering a new value. For example, if you select a Button element in the left panel, then the properties for that control are presented in the Value panel. If you click the Caption Property, its value becomes highlighted; you can type a new caption, and the new caption appears on the button.

1146 Part XII MAXScript and Plug-Ins

The Event Handlers panel lists all the available events that can be associated with the selected element. Clicking the check box to the left of these events can enable the events. For a button element, you can enable the pressed event. With this event enabled, the code includes a function where you can define what happens when this event is fired.

The menus and the main toolbar

At the top of the interface are some menu options and a main toolbar. The File menu also lets you create a new layout (Ctrl+N), save (Ctrl+S) layouts to a file, and open saved layouts (Ctrl+O). The Edit menu allows you to cut (Ctrl+X), copy (Ctrl+C), and paste (Ctrl+V) form elements. You can find these same features as buttons on the top toolbar.

The Layout menu includes options for aligning elements left (Ctrl+left arrow), right (Ctrl+right arrow), top (Ctrl+up arrow), bottom (Ctrl+down arrow), vertical center (F9), and horizontal center (Shift+F9); to space elements evenly across (Alt+right arrow) or down (Alt+up arrow); make elements the same size by width, height, or both; center vertically (Ctrl+F9) or horizontally (Ctrl+Shift+F9) in the dialog box; and flip. You can use the Layout Guide Settings menu command to specify grid snapping and spacing. Grids are enabled using the Toggle Grid/Snap button on the right end of the main toolbar.

You can also access these commands using a right-click pop-up menu when clicking on the left pane.

Toolbar elements

The toolbar along the bottom of the window contains the form elements that you can drop on the form. These buttons and elements include those shown in Table 48-1.

Table 48-1: Visual MAXScript Form Elements

Button

Element

What It Does

 

 

 

 

Bitmap

Lets you add bitmap images to a rollout

 

Button

Adds a simple button

 

Map Button

Adds a mapping button that opens the Material/Map

 

 

Browser

 

Material Button

Adds a material button that also opens the

 

 

Material/Map Browser

 

Pick Button

Adds a button that lets you pick an object in a

 

 

viewport

 

Check Button

Adds a button that can be toggled on and off

 

Color Picker

Adds a color swatch that opens the Color Picker

 

 

dialog box when clicked

Chapter 48 Automating with MAXScript 1147

Button

Element

What It Does

 

 

 

 

Combo Box

Adds a list with several items

 

Drop Down List

Adds a list with one item displayed

 

List Box

Adds a list with several items displayed

 

Edit Box

Adds a text field that can be modified

 

Label

Adds a text label

 

Group Box

Adds a grouping outline to surround several controls

 

Check Box

Adds a check box control that can be toggled

 

 

on or off

 

Radio Buttons

Adds a set of buttons where only one can be

 

 

selected

 

Spinner

Adds an up and down set of arrows that can modify

 

 

a value field

 

Progress Bar

Adds a bar that highlights from left to right as a

 

 

function is completed

 

Slider

Adds a slider control that can move from a minimum

 

 

to a maximum value

 

Timer

Adds a timer that counts time intervals

 

ActiveX Control

Adds a generic ActiveX control created by a separate

 

 

vendor

 

Custom

Adds a custom control that can be defined as

 

 

needed

 

 

 

At the bottom right of the window are two text fields that display the coordinates of the current mouse cursor position and the size of the rollout. The default size of the rollout is 162×300, which is the size needed to fit perfectly in the Command Panel.

Laying Out a Rollout

The rollout space, which appears gray in the left pane, can be selected and resized by dragging the black square handles at the edges of the form. As you change its size, its dimensions are displayed in the lower-right corner of the interface. With the rollout space correctly sized, you are ready to add elements to the space.

1148 Part XII MAXScript and Plug-Ins

To add one of these elements to the form, click the element button on the toolbar and drag on the form. The element appears and is selected. The selected element is easy to identify by the black handles that surround it. Dragging on these handles resizes the element, and clicking and dragging on the center of the element repositions it within the rollout space.

The Value and Events panels are automatically updated to show the values and events for the selected element. Values such as width and x-pos are automatically updated if you drag an element or drag its handles to resize it.

Aligning and spacing elements

Although only one element at a time can be surrounded by black handles, you can actually drag an outline in the rollout space to select multiple elements at once. With several elements selected, you can align them all to the left (Ctlr+left arrow), horizontally centered (Shift+F9), right (Ctrl+right arrow), top (Ctrl+up arrow), vertically centered (F9), or bottom (Ctrl+down arrow).

Multiple elements can also be spaced across (Alt+right arrow) or down (Alt+up arrow). To make several elements the same width, height or both, use the Layout Make Same Size menu command. The Center in Dialog menu aligns elements to the center of the dialog either vertically (Ctrl+F9) or horizontally (Ctrl+Shift+F9). The Flip command reverses the position of the selected elements.

Figure 48-15 shows a form with several aligned elements added to it.

Figure 48-15: You can add control elements to the form in the Visual MAXScript window.

Chapter 48 Automating with MAXScript 1149

Tutorial: Building a custom rollout with the Visual MAXScript Editor

Now you need some practice using this powerful tool. In this example, you use the Visual MAXScript window to lay out a rollout and code the script to make it work.

To create a custom rollout using the Visual MAXScript editor, follow these steps:

1.Open the BuildCube.max file from the Chap 48 directory on the CD-ROM. This file includes a simple sphere object.

2.Choose MAXScript New Script to open the MAXScript editor window. In the editor window, enter the following:

utility buildCube “Build Cube” ( )

This line creates a utility named buildCube. The rollout name will be Build Cube. Make sure to include a space in between the parentheses.

3.Choose Edit New Rollout from the window menu (or press the F2 key). The Visual MAXScript window opens. The properties for this rollout are displayed in the Properties panel. Drag the lower-right black square handle to resize the rollout form.

4.Click the spinner button on the bottom toolbar, and drag in the rollout form to create a spinner element. In the Properties panel, set the name to SideNum, set the caption value to No. of Side Objects, select the #integer for the type, and set the range to [1,100,5]. The range values set the lower, upper, and default values for the spinner. Then drag on the element handles to resize the element to fit in the form.

5.Click the spinner button again, and drag in the rollout form to create another spinner element. In the Properties panel, set the name to length, set the caption value to Side Length, select the #integer for the type, and set the range to [1,1000,50]. Then drag on the element handles to resize the element to fit in the form.

6.Click the button icon on the bottom toolbar, and drag in the rollout form to create a button below the spinners. In the Properties panel, set the name to createCube and the caption value to Create Cube. Then drag on the element handles to resize the button so the text fits on the button. Open the Event Handlers panel, and select the Pressed check box.

7.Drag over the top of both the spinners to select them both, and choose Layout Align Right (or press Ctrl+right arrow) to align the spinners. Figure 48-16 shows how the rollout layout looks.

1150 Part XII MAXScript and Plug-Ins

Figure 48-16: The rollout laid out in the Visual MAXScript window

8.With the layout complete, choose File Save (or press Ctrl+S) to save the layout, and then close the Visual MAXScript window.

The script code associated with the layout is automatically placed in the editor window.

9.Complete the script by entering the script commands immediately after the open parenthesis that appears on the line following the on createCube pressed do event, as shown in Figure 48-17. If you don’t have any original code that you want to enter, you can copy and paste the code from the BuildCube.ms file from the Chap 48 directory on the CD-ROM.

Figure 48-17: The MAXScript editor window is updated with the code from the Visual MAXScript window.