header
Welcome, Guest. Please login or register.
Did you miss your activation email?
   

+ Chapter 02 - MEL - Script Editor +



Instructor - Pradeep Mamgain

+ Overview +

Most of the time while creating MEL scripts, you will be writing and executing scripts inside of Script Editor. You can use script editor to cut and paste the whole scripts and execute them at once. All the operations you perform in the Maya interface are also recorded as MEL commands in the script Editor.


MAYA, MEL & PYTHON

Maya now supports Python. Python is simple, elegant and high level language. A language that is great for novices as well as for hard-core programmers. It can handle network programming, XML and databases. It also uses most powerful third-party modules. You can execute mel commands within Python in Maya. Almost all the MEL commands can be used within Python. However, Python syntax is quite different from that of MEL. There are certain MEL built-in functions that are not available in Python. Math function like abs, sin, cos.. etc and string functions like match, gmatch.. are not available in Python. However Python includes several libraries that can perform these functions.

Python syntax is different from MEL. For example MEL command "sphere -name mySphere;" would be re-written for Python as

import maya.cmds as cmds
cmds.sphere (name ="mySphere")

In order to enable MEL commands inside Python you must enter following line at the start.

import maya.cmds

You can automatically import MEL commands in Python by saving a Python script in Maya's script path. We are making a series of tutorials on using Python inside of Maya, so we request you to kindly get registered in the Forums. It would help us in informing you that when this series would be available on CG Sutra.


There are three ways to enter and execute the MEL commands.

  • The Command Line.
  • The Command Shell.
  • The Script Editor.

+ The Command Line +

The command line allows us to quickly execute MEL commands one at a time. The command line is located at the lower bottom part of the interface. From there you can execute MEL as well as Python commands. Click on the interface where MEL is written, you can now toggle between MEL and Python command line.

Commad Line
Figure 2.1 - MEL Command Line.

If command line is hidden, you can make it visible by selecting Display > UI Elements > Command Line.



Command Line Menu
Figure 2.2 - Display Command Line, if hidden.


+ The Command Shell +

Open the command shell from Window > General Editor > Command Shell.

Command Shell
Figure 2.3 - Open Command Shell.

Command Shell is something similar to DOS prompt. We will not explore it more as Script Editor is the most efficient medium for creating and executing MEL commands.

Command Shell Window
Figure 2.4 - Command Shell Window.


+ The Script Editor +

The Script Editor can be accessed by choosing, Windows > General Editor > Script Editor or click the Script Editor button in the bottom right of the main Maya window.

Script Editor Button
Figure 2.5 - Script Editor Button

Script Editor
Figure 2.6 - Script Editor Window.

For a brief description of Script Editor, see Figure 2.7.

Script Editor Description
Figure 2.7 - Script Editor Functions.

From Edit menu, you can access all standard windows menu commands like Undo, Cut/Copy, paste, Select All and Search and Replace.

Edit Menu
Figure 2.8 - Edit Menu

Almost every command Maya executes echoed in the history area. This is a great option to learn whats going on behind the curtain. By default, Maya only echoes commands that it thinks significant, however you can override this option by choosing History > Echo All Commands from the editor's menu.

Echo CommandLine numbers in errors and Show Stack Trace aid in the debugging of the scripts. Show Stack Trace is useful when you run inter-dependent scripts. It opens another window which lists errors and their line numbers in external script files. Batch render Messages when turned on, Batch render messages are displayed in the Script Editor. From History Output, you can choose whether you want output for MEL, Python or Both. Next set of commands is for suppressing the output. When you executed a command Maya displays a Command result, for example when you execute MEL command,

sphere -name mySphere;

Maya will echo following command result in the Script Editor.

// Result: mySphere1 makeNurbSphere2 //

You can also suppress Info, Warning and Error Messages. When Suppress Stack Window is turned on and Show Stack Trace is also enabled, results are returned to the output window instead of a separate stack window.

Figure 2.9 - History Commands.
Command MenuYou can create as many tabs, as you require. Click on New Tab to make a new tab. Tabs can be renamed and deleted from the command menu. Show quick help, displays a small window on the right bottom side of the editor. In the search box, type the command, for example, file. Editor will show quick list of parameters used with file command.

Quick Help
Figure 2.10 - Command Menu. Figure 2.11 - Quick Help

Other way of enabling quick help, is to double click on the keyword and right click; from the marquee menu select quick help. Script Editor will open quick help panel for you in the right bottom corner of the editor, as seen in Figure 2.11A..

Quick Help

Figure - 2.11A, Quick Help, Alternative way.

For see detail documentation, right click on quick help and select Show Command Documentation, as shown in Figure - 2.11B.

Documentation Help

Figure - 2.11B
, Displaying full command documentation.

+ How to get Help with MEL? +

One way of getting help you already know, as described above. Maya's help system is so extensive and powerful. You can get help on almost all MEL commands. Execute following MEL command.

Example 2.1 - Getting help on help.

help help;

The command output you will get in the script editor will be something as follows..

Example 2.2 - help command result.

help help;

// Result: Synopsis:

help [flags] [String]

Flags:
-q -query
-doc -documentation
-l -list
-lng -language String
-pdt -popupDisplayTime UnsignedInt
-pm -popupMode on|off
-ppt -popupPauseTime UnsignedInt
-rm -rolloverMode on|off

Above output is about getting help on help. Now if you want to see the documentation of the file command. Execute following command..

Example 2.3 -
help command with -doc parameter.

help -doc file;

This will open your default browser and display file command documentation, as shown in Figure 2.12.

file command documentation
Figure 2.12 - file MEL command Documentation.

You can access whole MEL command reference from Help (Maya Main Menu) > MEL command reference. Here you can browse the commands by category wise or alphabetically. A search text box is also available to search the command reference.




+ What Next +

Now we have understanding of how script editor works; in next chapter we will discuss about the MEL command and its syntax.

+ Download Project +

Dear guest, Only registered members can download projects/footages/scripts and Video files.Kindly get registered to download the files. It will also help us in informing you that when new tutorial/article/resource or cg news is available. Once you get registered downlaod link will appear here. - Downloaded times.

+ Save / Promote This Article/Tutorial/Information +

If you enjoyed this article your vote is always highly appreciated.

+ Other Info +

+ Discuss in Forums
+ Save / Promote This Article/Tutorial/Information +

Enjoyed this article/page/article/information? Your vote is always highly appreciated. If you own a website please create a backlink to CGSutra on your website. Get registered in the Forums and interact with other CGSutrians. You can also subscribe for CGSutra Google and CGSutra Yahoo Groups, so that we can inform you about new tutorials and developments. CGSutra Blog is updated daily and provides information about latest offsite CG tutorials, new plugin-software-movie releases, CG resources and inspirational artwork.

Subscribe to CGSutra Group

Powered by us.groups.yahoo.com




Add CGSutra blog and forum feed to your favorite feed reader application. Here is the link to the What is RSS and how to read feeds in feedreader application?
CGSutra.COM on Facebook




Fusion®, Maya®, Blender® and After Effects® are registered trademarks of eyeon, Autodesk , Blender Foundation and Adobe.

Content Copyrights © 2008, CG Sutra.

Copyright © 2007 Free Templates by Zymic - Free Web Hosting

Best Viewed in Mozilla Firefox, Safari, Opera and Google Chrome.