Using MEL Scripts


Once you've created a MEL script in the Script Editor, there are several ways to save it for future use. You can add it to the Shelf, save it as a .mel file in your Maya scripts folder, or even embed it in a specific scene using a script node. Script nodes can be useful because they execute in response to certain events, such as opening the scene file or rendering a frame. For example, you might use a script node to create and open a custom interface window whenever the scene file is opened.

In addition to creating your own scripts, you can find a wealth of free MEL scripts at Web sites like www.highend3d.com. Most of these scripts provide installation and use instructions at the beginning or are packaged with a readme file. Reading the scripts can also be useful for learning more about MEL.

To add a MEL script to the Shelf:

1.

Enter your script in the bottom pane of the Script Editor (Figure 17.23).

Figure 17.23. This script will cause the selected objects to be displayed as wireframes.


2.

Select the text of the script.

3.

Click and drag the selected text to the Shelf.

A new MEL icon appears on the Shelf (Figure 17.24).

Figure 17.24. When you drag a script to the Shelf, a new MEL icon is created for the script.


Tips

  • If you add multiple MEL scripts to the Shelf, it can be difficult to tell them apart. You can use the Shelf Editor to add a short name to the icon and to change its tooltip to something more descriptive.


To change a Shelf icon's name and tooltip:

1.

Click the arrow to the left of the Shelf, and select Shelf Editor from the pull-down menu that appears.

The Shelves dialog box opens with the current shelf automatically selected.

2.

Click the script whose icon you'd like to edit (Figure 17.25).

Figure 17.25. From the Shelf Contents tab, select the script that you would like to edit.


3.

In the Icon Name field, enter a name for the icon, and press . Names longer than four characters may be truncated when displayed.

4.

In the Label & Tooltips field, add a comment, and press .

5.

Click Save All Shelves.

The icon in the Shelf now has a name (Figure 17.26), and when you hold the cursor over the icon, its new tooltip is displayed.

Figure 17.26. The icon name is displayed by the script's icon.


To save and source a MEL script:

1.

Enter your script in the bottom pane of the Script Editor. To enable you to call the script from Maya later, it should be defined as a global procedure (Figure 17.27).

Figure 17.27. This simple procedure displays the text "Script successfully saved and sourced!" when it's called.


2.

Select the text of the script.

3.

From the Script Editor's File menu, choose Save Selected.

A Save dialog box opens for the Maya scripts directory.

4.

Enter a name for the script, and click Save.

5.

From the Script Editor's File menu, choose Source Script.

6.

Navigate to the scripts folder, if necessary, and select the script you just created; then, click Open.

The script is sourced, meaning that you can now access the procedure defined in it as a MEL command from Maya.

7.

Enter the name of the script's global proc in the Script Editor, and press on the numeric keypad.

The procedure defined in the saved and sourced script is executed (Figure 17.28).

Figure 17.28. Once the script has been saved and sourced, entering scriptTest( ) in the Script Editor displays this message.


To create a script node:

1.

From the Window menu, select Animation Editors > Expression Editor.

The Expression Editor opens.

2.

From the Expression Editor's Select Filter menu, select By Script Node Name.

3.

In the Script Node Name field, type HelloWorld.

4.

In the Script field, enter the following script: confirmDialog -message "Hello World" -button "OK"; (Figure 17.29).

Figure 17.29. Script nodes need to be created in the Expression Editor using the By Script Node Name filter.


5.

Click Create.

The HelloWorld script appears in the Script Nodes section of the Expression Editor.

6.

From the Execute On menu, select Time Changed (Figure 17.30).

Figure 17.30. Changing the Execute On property of the script node to Time Changed makes the script run whenever the time slider is moved.


7.

Move to a new frame in the timeline.

When the current frame is changed, it triggers the HelloWorld script, and the dialog box appears (Figure 17.31).

Figure 17.31. When you move to a new frame in the timeline, this dialog box appears.


To delete a script node:

1.

Open the Expression Editor.

2.

From the Select Filter menu, select By Script Node Name.

3.

In the Script Nodes section, click the name of the script node you would like to delete.

4.

Click Delete.

The name of the script node disappears from the Script Nodes section.




Maya 7 for Windows and Macintosh(c) Visual Quickstart Guide
Maya 7 for Windows & Macintosh
ISBN: 0321348990
EAN: 2147483647
Year: 2006
Pages: 185

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net