Mel - Maya Embedded Language

<HOME>   <PREVIOUS>   <NEXT>

Variables

Like any other programming language, Maya provides the user with the ability to temporarily store information through variables. An easy way to look at variables is to see them as a box that we dump and pull information into and from.

Data Types that can be used with Variables

int
float
string
vector
array
matrix

Declaring Variables

When declaring a variable there is a specific format you need to use. First declare what sort of variable you are using. If you do not declare what sort of variable you are using Maya will automatically assign the type. Next use a $ sign followed by the name.

There are a few restrictions on naming. You can not start with a number. You can not have whitespaces, or special characters. You can however put a number in the name after the first character.

int $myInt = 1;

string $myString = "Hello Jello";

It is important to remember to place a semicolon at the end of each statement. This is how Maya knows when one command statement starts and another begins.

If you are unsure what a variable type is, use the whatIs command to find out.

int $myInt = 1;
whatIs "$myInt";
// Result: int variable //
You can assign a value to a variable by getting information using the query command

float $ballRadius = `polySphere -query -radius "myBall"`;

Exercise:Create a variable for a the name of a cube. Make a polyCube using the variable. Make variables for height, width and depth. Edit the polyCube using the new variables.