'Maya'

 
'mel ShapeEditor'
by
Martin Andersson


In this tutorial I will go through how I created the final3 multiple shapeEditor. warning: this tutorial will be
extremely 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 rookie stuff and just dive into the
reasons why I picked this and that solution, but then I decided to go 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:


Commands:

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 help files. These are awesome. 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 help files. 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 help Files.

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 parentheses 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 help files 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.


Variables:

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