In this tutorial I will go through how I created the final3 multiple shapeEditor. warning: this tutorial will be
extremly long because I skip lines when I show examples. Experienced MEL scripters can skip a lot of this, but
for an unexperienced one it will benefit them to have it listed like this.

MEL is extremely powerful. If you have the time and wish to learn MEL I welcome you to an incredible world!

Before you jump into scripting there are some stuff to consider:

  • Get an external textEditor ( "ultraEdit", "conText" ) or plug-ins ( "mel studio pro", "mel source") to script with because the script editor in maya can't be used for this task... It lacks... everything!
  • Will the script be used by others? If so, write code other people can understand! Give important
    sections comments.

When I first decided to write this tutorial I though that I should skip all the rookiestuff and just dive into the
reasons why I picked this and that sollution, but then I decided togo through more stuff so it will be fit for a
bigger mass of artists. I'll probably go back and forth between UI and commands because I go from top to
bottom when I write the script.

If you have no experience with MEL we should go through some basic stuff. If you have some experience, skip
this part:


 
 

The simplest thing you can find in MEL are the commands. Maya is build up by tons of commands. Every time
you do something in Maya at least one commands is executed, mostly several. To figure out which commands
Maya executes you should turn on "echo all commands" in the script editor. ( Script --> Echo all commands )
Your number one sources when it comes to MEL are the scriptEditor and the helpfiles. These are awsome.
Try creating a polygon sphere while you pay attention to the history in the script editor. What you will see when
it is created is:

polySphere -r 1 -sx 20 -sy 20 -ax 0 1 0 -tx 2 -ch 1;

It returned a bunch of code here, but the essence is "polySphere". All the other things here are flags and values. You see a command is built up like this:

command [flags] [name]

The -r flag is the radius with a value 1 here and -sx and -sy are divisions in those axes with values of 20.
Notice that the command polySphere does not have a name. If you look in the helpfiles for polySphere you
see that this command actually does not have a name. ( you can use the flag "name" to name the sphere,
but when I say name here I mean the ID at the end [name] )If you are insecure, check the helpfiles. They are
extremely helpful!

If we look at the window command the helpfiles show us this:

window [flags] [windowName]


There are also different modes for the flags. "Create" ( which is default ) , "Edit", "Query" and "Multiple use of
flag". I'm going to go through some of them in the following example.

If we take a look at the command window we can add many flags, I'll use -width and -height as an example.

//We're going to create a window with a width of 100 and a height of 200.
window -width 100 -height 200 myWindow;
showWindow myWindow;

Now, what we did was create a window with a width of 100 and a height of 200. We also gave the window a
name, "myWindow" . This will ID the window later like when we want to open it ( "showWindow myWindow") .
You see, the window command doesn't show us the window, it just creates it in the background. To actually
be able to see it, we have to tell Maya that we want to see it by using the command showWindow. So
showWindow
is another command you can look up in the helpFiles.

If we look at the command window again and check out the flags we see that there's a flag called
"-widthHeight". You can also see that inside the parantheses the short form for -withHeight is -wh. This
means that we can choose to write the long form or the short form. There are disagreements whether you should use short or long. Personally I like to use short ones because the code will be shorter. On the other
hand the long name will be more explanatory. When I edit scripts I tend to jump back and forth between
Maya and the helpfiles anyway...
Let's take another look at the window command:

//I want to know the width and the height of a window.
window -q -wh myWindow;

If you look at the history in the scriptEditor you get "result: 100 200". Of course we knew that, but you can use
this for any window. If we scaled the window the result would have been different. When we want to gather
information from a layout or other UI elements we have to put it in "query"- mode. Say we wanted to get the
label of a button we'd write:

button -q -l myButton;

Now, let's try and edit the window size. If you're paying attention you'll know that we have to put the layout/
element in edit - mode. The code would look like this:

window -e -wh 150 100 myWindow;

Now we edited the size to a new value. Keep the window open and change the values. You can see the window-
size change realtime.

 

 
 

Say you're writing a letter in a bottle. What you do then is you write a letter and then you store it in the bottle
before you throw it in the sea. You can look at variables the same way. You create a variable to store some
data in it. Maya has several different types of variables and here's a look at some of them. I'll use the prefix
"ma" for most of my stuff. ( My initials )

  • string
  • array
  • int
  • float
  • vector

This is what the helpfiles says:

Strings are sequences of characters. The literal representation of a string is surrounded by double quotes.
For example:
"MEL is fun!"
"abcdef012345"
":<>()&^%ABC"

A string can hold almost anything. If I want to create a string holding my name and some silly numbers, I'll
type:

string $ma_stringVar = "Martin123";

If you want to check what the string holds you can simply use the print command to check it. Maya will print
the value and return it in the history.

print $ma_stringVar;

This will print Martin123

Strings can also hold commands. If you want to execute a command and cast it ( cast = store the value INSIDE the string) to a string you have to put the command between backquotes ``.

string $ma_windowString = `window -t "windowTitle" windowID`;
showWindow $ma_windowString;

Since we did cast the value ( window command ) to the string we can call the string later like we did with the showWindow- command.

We can also use a string like this:

string $ma_windowName = "ma_superWindow";
window -t "myWindow" -wh 100 100 $ma_windowName;

If you read the code one step earlier you can see that I wrote the name "windowID". This time I used
$ma_ superWindow because I had this declared ( declare = Declaring the variable tells Maya you intend to use
a variable with this name, and specifies the type of values the variables can hold.) earlier and therefore I could
use it now.

 

 
 
 
 

The content of this tutorial is copyrighted by law.
Reproduction of the content without permission
will result in legal prosecution.

www.final3.com © 2006