2010

Table Of Contents
Using creation expressions to set a constant color . . . . . . . . 645
Using runtime expressions . . . . . . . . . . . . . . . . . . . . . 646
Modifying runtime expressions . . . . . . . . . . . . . . . . . . 648
Beyond the lesson . . . . . . . . . . . . . . . . . . . . . . . . . 649
Chapter 13
Scripting in Maya . . . . . . . . . . . . . . . . . . . . . . . . 651
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 651
Some basic concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . 652
Preparing for the lessons . . . . . . . . . . . . . . . . . . . . . . . . . 655
Lesson 1: Commands in MEL . . . . . . . . . . . . . . . . . . . . . . 656
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 656
Entering MEL commands . . . . . . . . . . . . . . . . . . . . . 657
Observing script history . . . . . . . . . . . . . . . . . . . . . . 658
Modifying object attributes . . . . . . . . . . . . . . . . . . . . 661
Editing Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . 664
Beyond the lesson . . . . . . . . . . . . . . . . . . . . . . . . . 665
Lesson 2: Saving scripts to the Shelf . . . . . . . . . . . . . . . . . . . 666
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 666
Setting up the scene . . . . . . . . . . . . . . . . . . . . . . . . 667
Recording the script history . . . . . . . . . . . . . . . . . . . . 668
Compare the rendered images . . . . . . . . . . . . . . . . . . 670
Saving the history as a button . . . . . . . . . . . . . . . . . . . 671
Beyond the Lesson . . . . . . . . . . . . . . . . . . . . . . . . . 673
Lesson 3: Using Variables in MEL . . . . . . . . . . . . . . . . . . . . 674
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 674
Setting up the scene . . . . . . . . . . . . . . . . . . . . . . . . 674
Storing scene information . . . . . . . . . . . . . . . . . . . . . 675
Create a row of barrels . . . . . . . . . . . . . . . . . . . . . . . 677
Stacking the row of barrels . . . . . . . . . . . . . . . . . . . . . 678
Using MEL built-in functions to calculate the Y offset . . . . . . 679
Creating dynamics with MEL commands . . . . . . . . . . . . . 681
Beyond the lesson . . . . . . . . . . . . . . . . . . . . . . . . . 683
Lesson 4: User interface creation and procedures . . . . . . . . . . . . 683
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 683
Creating a window . . . . . . . . . . . . . . . . . . . . . . . . . 684
Window naming . . . . . . . . . . . . . . . . . . . . . . . . . . 686
Introduction to procedures . . . . . . . . . . . . . . . . . . . . 689
Loading a script file . . . . . . . . . . . . . . . . . . . . . . . . 691
Linking the user interface . . . . . . . . . . . . . . . . . . . . . 695
Saving the script . . . . . . . . . . . . . . . . . . . . . . . . . . 700
Using the saved script file . . . . . . . . . . . . . . . . . . . . . 701
Beyond the lesson . . . . . . . . . . . . . . . . . . . . . . . . . 702
Lesson 5: Using Python in Maya . . . . . . . . . . . . . . . . . . . . 703
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 703
Entering Python commands . . . . . . . . . . . . . . . . . . . . 704
Using flags in Python . . . . . . . . . . . . . . . . . . . . . . . 707
xii | Contents