Keep up-to-date with Free tutorials!!


Sign up to our twice-monthly newsletter today for the latest tutorials, interviews and product information.

Sign me up to receive third-party emails from 3dtotal's partners, too!

- Latest news
- Exclusive Shop Offers
- Preview early content
- Plus much more


Not Ready to take that step? OK, Why not just Subscribe to the RSS Feed

submit tutorial
1 | 2 | 3 | 4 | 5 | 6
mel ShapeEditor

| Your Rating:
rating star nonerating star nonerating star nonerating star nonerating star none
(Score 0 out of 5 after 0 Votes)
| Comments 0
Date Added: 9th December 2009
Software used:
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:


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.


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 help files says:

Strings are sequences of characters. The literal representation of a string is surrounded by double quotes.
For example:
"MEL is fun!"

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.

continued on next page >

1 | 2 | 3 | 4 | 5 | 6
Related Tutorials

Modelling and Rigging a nut and bolt

by Martin Andersson
published on 2007-04-12

Keywords: nut, bolt, modeling, maya,

rating star fullrating star fullrating star fullrating star fullrating star full (1)
Comments 0 Views 94882

Using Driven Keys to create a handController

by Martin Andersson
published on 2009-12-09

Keywords: drive, keys, hand, controller, maya,

rating star nonerating star nonerating star nonerating star nonerating star none (0)
Comments 0 Views 31481

Setting up animation controls in Maya

by Martin Andersson
published on 2009-12-09

Keywords: animation, controls, maya,

rating star fullrating star fullrating star fullrating star fullrating star full (1)
Comments 0 Views 26800

Mental Ray Texturing

by Florian Wild
published on 2009-12-09

Keywords: texture, texturing, maya, mental, ray,

rating star nonerating star nonerating star nonerating star nonerating star none (0)
Comments 0 Views 26956
Readers Comments (Newest on Top)
no comments!
No comments yet. Be the first to comment!
Add Your Comment..