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

+ Chapter - 03 - MEL - The MEL Command Syntax+



Instructor - Pradeep Mamgain

+ Overview +

The most fundamental aspect of MEL is command. We have already learned where to enter MEL commands to execute them; in this chapter we will gain understanding of MEL commands.

+ How to make a Shelf button for a script? +

Maya Shelf is a customizable collection of tools located directly below the status line, useful for storing tools and frequently-used items. If you use a script often, make a shelf button for that script so that you can access it easily. You can do so by one of two ways. Select the script code in the script editor. Now, either drag the selection with MMB up to the shelf or select File > Save Script to Shelf from Editor's File menu. Maya will place a MEL button in the shelf. Now you can access your favorite script with a click of the button.

+ Relationship between the Interface and MEL command +

Whenever you do anything with the interface or tools, MEL commands are executed. Let us understand the relationship between the Interface and corresponding MEL command. Open a new Maya document. Go to Create > Polygon Primitive > Sphere and then click on the option box. Click on the create button.

Sphere Command
Figure 3.1 - Sphere command, Interface.

Now check the script editor, in the History pan we will see text similar to that in Example 3.1.

Example 3.1 - sphere command feedback in history pan.

polySphere -r 1 -sx 20 -sy 20 -ax 0 1 0 -cuv 2 -ch 1;
// Result: pSphere1 polySphere1 //

Now relate the Figure 3.1 with Example 3.1, you would notice that MEL has executed command polySphere, which is the actual command. Other things next to polySphere commands are flags. They are easily distinguished by the "-" symbol that prefaces them. A flag allows us to set the values for different parameters of the command. In Example 3.1...

-r : radius of the sphere, 1 unit in this case.

-sx : number of subdivisions in the X direction of the sphere, 20 in this case.

-sy :number of subdivisions in the X direction of the sphere, 20 in this case..

-ax : primitive axis used to build the sphere, Y in this case.

-cuv: create uvs, it can be 0,1 or 2. 0 - no UVs will be generated (No texture to be applied). 1 - UVs are created with pinched at poles. 2 - UVs are created with sawtooth at poles.

-ch : construction history on or off, on in this case.

You can convert flags or argument into more readable format. Following command will be equivalent of Example 3.1.

Example 3.2 - Long Argument Names.

polySphere -radius 1 -subdivisionsX 20 -subdivisionsY 20 -axis 0 1 0 -createUVs 2 -constructionHistory on;

+ Command Modes +

MEL commands have three modes create, query and edit. By default the command will be in create mode. If you want to extract value of any flag, you will use query mode. To extract value of radius of polySphere we just created, use text as seen in Example 3.3. In history pan, you would see result as 1.

Example 3.3 - Value of radius flag of polySphere.

polySphere -query -radius;
// Result: 1 //

To edit the flag values use -edit flag. Now if we want to change the radius to 5 units, we will execute command as seen in Example 3.4.

Example 3.4 - polySphere command, Edit mode.

polySphere -edit -radius 5;
// Result: Values edited. //

Always place a semicolon at the end of the MEL command. It tells Maya that this commands ends here. If you don't place a semicolon between two MEL commands, an error will occur.

Whitespace (spaces, tabs, and newlines) is ignored by MEL, except inside strings. A block in MEL is surrounded by a pair of curly brackets. All statement inside a block must end in semicolons, even if it is inside the if statement. For example code if ($objHeight < 10) { print ("Height is less then 10)} will generate a syntax error. Correct line of code will be if ($objHeight < 10) { print ("Height is less then 10);}.

+ Expressions +

An expression is a series of values and operators that evaluate a new value.

4 + 5 => 9
(10 < 5 ) => 0 (false)
(5 < 10 ) => 1 (true)
string $name="James Bond" => James Bond


+ Operators +

MEL uses three types of operators binary, unary and ternary. A binary operator requires two operands. One before the operator and one behind it.

$i=8;

= is the operator having operands on either side.

THE OPERATORS and VARIABLES

A list of MEL operators and corresponding supported variable types.

+ => Addition => I F V S M

- => Subtraction => I F V M

* => Multiplication => I F V M

/ => Division => I F V

%=> Division Remainder => I F V

^ => Cross Product => V

LEGENDS => I - Integer, F - Floats, V - Vector, S - String, M - Matrix


A unary operator requires a single operand, either before or after the operator.

$i++;

Increments the value of i by 1. This arithmetic shortcut is used by programmers quite a lot. MEL also has ternary operator.

condition ? exp1 : exp2

$i=10;
print($i>5 ? " Thats True " : "Thats False"); // Displays, "Thats True"


+ Operator Precedence +

The following shows order of operator precedence in MEL. Operator in same row has equal precedence. Left most operator is evaluated first, if a statement has more then one operators of equal precedence.

Operator Precedence
+ Blocks +

A block is a group of statements. Blocks are surrounded by curly brackets. We will learn more about blocks in "Introduction to Programming Concepts" chapter.

+ What Next ?+

Now we have the understanding of the MEL command and how we can pass arguments to it, in the next chapter we will explore the Maya Prompt and will create a maya file from Maya prompt i.e. without starting Maya Interface.

+ 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

# Forum Info #

Chat with cgRokrs - Online

Supports forum boards as channels, a public channel, multiple languages, multiple themes and much more !!

# Board Topics #

Recent Topics Recent CG News

# Board Stats #

Boards : 33, Categories : 7 , Members : 1222, Topics : 135, Posts : 242

# Users Info #

Please welcome our newest friend blackmamba.

Currently (5) users online in forums; (5) guests and (0) users.

Users Online :
Fusion®, Maya® and After Effects® are registered trademarks of eyeon, Autodesk and Adobe.

Content Copyrights © 2008, CG Sutra.

Copyright © 2007 Free Templates by Zymic - Free Web Hosting - Best Viewed in Mozilla Firefox