Alias Maya Tutorials Maya 3D Mel Scripting

Document Sample
Alias Maya Tutorials Maya 3D Mel Scripting Powered By Docstoc
					 Contents




MEL                                                                               Introduction
Introduction
                                                                                  What is MEL?
Programming Basics
                                                   q   Eveything you do in Maya with mouse clicks and keyboard
Procedures                                             inputs is a MEL command.
                                                   q   MEL is a scripting language, similar in syntax to C. It
                                                       contains not only a complete range of 3D operation
User Interface
                                                       commands, but also a rich set of UI creation commands. In
                                                       fact, all of Maya's dialog windows are written with MEL.
UI Design                                          q   Typical uses:

MEL commands                                                 Repetitive task. Eg. renaming many objects.
                                                             r

                                                           r Expression aid. Eg. offset animation.

                                                           r Creating special Hypergraph nodes. Eg. time node.

                                                           r Custom UI (see the User Interface section).

                                                           r Some tasks can only be done through MEL. Eg.

                                                             namespace management.
                                                   q   You would typically execute MEL commands and scripts
                                                       once-off. Although you can write dynamic MEL scripts, they
                                                       are usually very slow to execute.


                                                                            MEL input methods
                                                 1. Type the following command into the command line at the
                                                    bottom of the Maya window:

                                                             polyCube -tx 0 -ch 0 -n cube1

                                                    and press Enter to execute the command.
                                                 2. Delete the cube and open the script editor (either through
                                                    Window ··> General Editors ··> Script Editor, or through
                                                    the Script Editor icon  located at the bottom right of the
                                                    Maya window).

                                                       The top area of the script editor is the history panel; it
                                                       echoes MEL commands that you've executed, and also
                                                       displays error messages. The bottom area is the input
                                                       panel; this is where you type MEL procedures. Take note
                                                       that the key pad Enter is for typing new line, while the
                                                       number pad Enter is for executing the script.

 http://cade.scope.edu/courseware/notes/mel/index.html (1 sur 4)03/08/2004 14:33:34
Contents


                                                      Type the following lines in the input panel:

                                                            int $count;
                                                            string $cubename;
                                                            float $xpos, $zpos;

                                                            for( $count = 1; $count <= 50; $count++ )
                                                            {
                                                                $cubename = "cube" + $count;
                                                                $xpos = rand( -10, 10 );
                                                                $zpos = rand( -10, 10 );

                                                                    polyCube -tx 0 -ch 0 -n $cubename;
                                                                    move $xpos 0 $zpos;
                                                            }

                                                   and press the number pad Enter to execute the procedure;
                                                   you may also execute the procedure by choosing Edit ··>
                                                   Execute from the script editor's top menu.
                                                3. Look for the above block of commands in the history panel
                                                   and highlight it. At the script editor's menu, choose File ··>
                                                   Save Selected. The saved MEL script is a simple text file
                                                   that you can edit with Notepad.

                                                   Delete all the cubes, and pick File ··> Source Script from
                                                   the script editor menu; select the script you just saved.
                                                4. Quit Maya.

                                                      Move the MEL script to $MAYA_APP_DIR\3.0\scripts. You
                                                      should create a folder called "maya" under your home
                                                      folder, and set the MAYA_APP_DIR environment variable
                                                      to it. If this variable is not set, Maya will assume it's C:
                                                      \WINNT\Profiles\username\maya.

                                                      OR,

                                                      set the MAYA_SCRIPT_PATH environment variable to the
                                                      folder where you place your MEL scripts.

                                                      After you've set up the environment, launch Maya and type
                                                      in the command line

                                                            source script

                                                   where script is the name of the MEL script.
                                                5. You may store a block of MEL commands in a shelf: just
                                                   highlight the commands in either the command line or the
http://cade.scope.edu/courseware/notes/mel/index.html (2 sur 4)03/08/2004 14:33:34
Contents


                                                      script editor, and then middle-mouse-button-drag the
                                                      highlighted text to a shelf. You can then execute the
                                                      commands by clicking on the stored shelf icon.


                                                                                     Script node
                                                1. Create a sphere with a radius of 3 units and move it up in Y
                                                   by 4 units.
                                                2. Animate the camera around the sphere.
                                                3. Open Window ··> Animation Editors ··> Expression
                                                   Editor.

                                                      In the expression editor, choose Select Filter ··> By Script
                                                      Node Name. Type a name of your choosing into the
                                                      Expression Name text field. Then in the Script field type
                                                      the following command,

                                                            file -i -typ "mayaBinary" "C:/courseware/examples/
                                                            maya/scenes/background.mb"

                                                      and click on the Create button.

                                                   Choose Execute On ··> Software Render, and make sure
                                                   the script execution time (located just under the Execute
                                                   On control) is set to Before.
                                                4. Set up the render globals to render the animation, and
                                                   save the scene.
                                                5. Quit Maya, and render the scene through command-line.

                                           A script node is a hypergraph node containing MEL commands
                                           that execute automatically at a crucial moment in the evaluation
                                           of the Maya scene. In the above exercise, we've created a script
                                           node that imports a pre-made scene just before rendering begins.

                                           A script node can only be selected via the MEL command
                                           "select". After it's selected, you can see it in the hypergraph.


                                                                                     Script Job
                                                1. Create some objects and name one of them "specialobject".
                                                2. Deselect everything.
                                                3. Run the following command:


http://cade.scope.edu/courseware/notes/mel/index.html (3 sur 4)03/08/2004 14:33:34
Contents


                                                            scriptJob -e SelectionChanged "select -r specialobject"

                                                   and note the number that is printed in the command
                                                   response field.
                                                4. Try to select any object. Note that you can't select anything
                                                   other than the special object. In fact you can't even
                                                   unselect it.
                                                5. You can remove the job with the command

                                                            scriptJob -k job-number

                                                      where job-number is the command response number you
                                                      noted above.

                                           Although script jobs are sometimes useful, they can make your
                                           scene cryptic to someone who isn't in the know. So you should
                                           use them carefully in a collaborative environment.

                                           Script jobs are not saved with the scene.




http://cade.scope.edu/courseware/notes/mel/index.html (4 sur 4)03/08/2004 14:33:34

				
DOCUMENT INFO
Shared By:
Categories:
Stats:
views:122
posted:6/24/2010
language:English
pages:4