Maya Mel Modeling

1. Using Mel Commands

MEL is Maya's Scripting Language. All maya menus are shortcuts for using the programing language MEL. You can track your commands by opening the MEL script window and then try a few operations within the program. You will see the commands accumulate.

In the Script Window you can experiment with commands. Below I am giving a command that I want maya to choose a random number between 0 and 6 and print it. In order to run the script you need to type in the command and press the ENTER key (not the return key). If you select the text before you hit enter - you can re-run the script over and over again without retyping.

Below - Now i'm specfying that the random number must be converted to an integer (a whole number before it is returned.

Below i'm using a command that creates a cube with a random height, width and depth. Each time i run the script it creates another cube.

Below i'm using a command that creates a cube with a random height, width and depth. Each time i run the script it creates another cube.

Below i'm using a command that creates a cube with a random height, width and depth. Each time i run the script it creates another cube.

Below i'm using a 'for loop' command that helps me repeat a command 10 times. It first defines a value for the variable "i" then each time it goes through the script it increases the value of "i". Because it is also using "i" to pace the cube in space - it begins to spread the cubes across the scene.

for( $i=0; $i<10; ++$i )
{
polyCube -w (rand(4)) -h (rand(4)) -d (rand(4));
move -r (2*$i) 0 0;
}

It would be interesting at this stage to begin to experiment with other functions like gauss, noise, sphrand - you may read about these here.

Below, i've increase the loop to 1000 - and specified x y and z placement of each cube.

Below, I'm nesting one loop inside of another to add depth- and using the noise function to make a curvey line as it duplicates.

for( $i=0; $i<300; ++$i ) {
              polyCube -w (rand(1, 4.2)) -h (rand(1, 4.2)) -d (rand(1, 4.2));
              move -r (noise($i*.1)*30) ($i*.4) 0 ;
                      for ( $surf= 0; $surf <10; ++$surf )
                        {
                            duplicate -rr; move -r 0 0 (rand(-3, 3)) ;
                        }
}



Script for instant city:

 

for( $i=0; $i<50; ++$i )
{
for( $q=0; $q<50; ++$q )
{

$bldgH = rand(1, 5); // specifies max and min bldg height
$bldgW = rand(2, 3.5); // specifies max and min bldg height
$bldgD = rand(3.5, 3.5); // specifies max and min bldg height

polyCube -w ($bldgW) -h ($bldgH) -d ($bldgD);
move -r (5*$i+ ($bldgW/2)) ($bldgH/2) ($q*5);
}
}

Joshua Mosley 2013