Maya> mel>Mel Procedures

Mel Procedures

Share |

MEL procedures are a whole bunch of scripts that are put together into one main script. In this tutorial I'll explain as simply as I can how to create a procedures script.

The Syntax

Syntax is how you write you code, and in what order. The syntax for writing procedural script that'll be written for later use looks like this;





Let's look at one in it's finished form;



Copy and paste this code into the script editor. (click the script editor icon at the end of the command line)

click to enlarge

Hit "enter" on the number pad, or, in the script editor, go to command>execute. This compiles the code. Nothing should happen. Now, in the command line, type in makesphere. You should see a sphere appear on you screen. This'll happen whenever you type that command in. This is pretty useless considering you can just create a sphere from the shelf. You might be wondering why we put forward slashes in. Technically we don't have to. The reason I put those there is so the compiler, Maya, won't think that these notes, or comment lines, are code that it should compile. Now let's make this code useful. Let's take advantage of the fact you can add values to your procedure.

Adding Values

As noted in the syntax, you add the values in between the two brackets ( ). We're going to take advantage of this. The first thing we're going to have to add is " int $radius ". The " int " says that this value is an integer. And the $radius means that this is the name of the value. You always have to add $'s on value names. Now, the code should look like this without slashes;



Note; Always end your line of code with ' ; '

Now, we need to add the int $radius to the inside of the code. This way, this value can be recognised inside the code.

Now your code should look like this;



Now we need to assign our radius value to the polygonal sphere's radius. When in code, the sphere's radius is referred to as r. We're going to write r = radius. Here's how you write it as code; polySphere -r $radius; Now, here's what it looks like in code;



Now, write the code in the script editor and compile it. Now type in the command line makesphere 2. It'll create a sphere with the radius of 2. Now type in makesphere 1. This just proves that the script's working. In part two we'll learn how to add more values to this code.

turbosquid
Visit The3dStudio.com
Home Tutorials About the Author Site Map
User Agreement Privacy Policy ©2015