Mel - Maya Embedded Language

<HOME>   <PREVIOUS>   <NEXT>

Procedures

Procedures can be looked at as a custom set of structured MEL commands that perform a specific action. If you have programmed before you could make the connection that a MEL procedure is much like a function in another languages. A nice aspect of a procedure is that you can feed it a variable and have it return data. There is one stipulation when using procedures in Maya, you can not use a procedure within a procedure.

Simple procedure
proc hello()
{
     print ("\nHello World");
}
Hit enter and then type hello();


Simple procedure with user input
proc hello(string $name)
{
     print ("\nHello World, let us clap our hands for "+$name);
}
Hit enter and type in hello("Walter the Great");
This procedure takes user input. When specifying a string value you need to place the string in quotes.

Passing Values through a procedure
proc int myVal(int $a, int $b)
{
     int $c = $a + $b;
     return $c;
}

//call the procedure and send it some values
int $returned = myVal(10,20);
print $returned;

When using a procedure that returns a value, specify what data type the return value is in the declaration of the procedure.

<Top>