Adverti horiz upsell
Conversational MEL Part 1
Conversational MEL Part 1
JamesPiechota, updated 2006-11-29 07:04:17 UTC 47,441 views  Rating:
(7 ratings)
Page 1 of 4

Conversational MEL Part 1




Topics Covered: MEL commands, flags, and argument; Maya scripting UI;
Sample Script: A window to hold common tasks


This is the first of several tutorials on MEL. We�ll be starting from the very beginning with this article, and quickly picking up speed in the future. By the end of this article you will have learned what a MEL command is and how to interpret its different parts, how to quickly automate simple tasks using MEL, and, finally, how to build a small piece of custom UI.

What Is Mel?

Technically MEL stands for �Maya Embedded Language� and could be described as �an interpreted scripting language that interfaces directly with Maya�s core libraries�. Besides being boring enough to make you question reading this article further, those definitions miss the point: MEL is an easy way to take your art to the next level. Everything you do, and almost everything you see, in Maya is driven by MEL. Menu items, check boxes, sliders, heads up display, outliner, attribute editor, etc... All of it is created using MEL. When you check a check box, slide a slider, manipulate a manipulator, or do pretty much anything in Maya, a little bit of MEL is executed. This tight relationship between MEL and the rest of Maya means MEL is a powerful tool for doing such things as:

    • Automating repetitive tasks and reducing your �click-count� - with MEL you can write a script that performs far more clicks and drags than you could do in your typical 100-hour work week!
    • Building custom UI to suits *your* needs - if you�ve complained about the apparent stupidity of some part of Maya�s UI, then MEL is for you!
    • Leverage the power of modern computers to perform advanced math and invent the next great effect or tool!
    • And much more!

    I realized I�ve dodged the question posed big and bold at the start of this section: �What is MEL?� We�ll get into some of the details later, for now it�s enough to know that MEL is powerful and, as you�ll hopefully see by the end of this article, very accessible.

      Command Line and Script Editor

      Now that I�ve got you hooked with that hand-wavy, �one MEL to rule them all� talk - it�s time to bring things crashing back to reality: MEL is a programming language. It is made up of commands, flags, arguments, loops, conditionals and other scary (boring?) sounding things. To use MEL you will need to type out commands and pass them off to Maya.

      But it�s not that hard - really. In fact you can do it right now. If you look at the bottom of your Maya window you should see two fields called the Command Line and the Command Feedback:

      Command Line and Status Feedback

      The Command Line is an input field into which you can type small chunks of MEL quickly. The Command Feedback displays information about recently executed MEL commands and will turn red if there were any problems.

      That�s all you need to know to get started - why don�t you give it a whirl, type something into the Command Line and hit Enter ...


      ... Done? Chances are if you�ve never written any MEL before you got an error - maybe you�re a wise guy and typed �something� into the Command Line, or maybe you entered something more like this:

      Command Line Error

      If so, you�ll note that the Command Feedback field is red indicating that there was an error:

      Error: line 1: Cannot find procedure "alsdjf".

      I mentioned before that MEL is made up of commands (sometimes referred to as �procedures�). A MEL command is a special word or series of words that can be used to tell Maya to take some action. This is similar in concept to the spoken commands you encounter daily: �Sit�, �Work late tonight�, �One shot� - these are all spoken commands that you might use with dogs, employees, or friends.

      When you speak one of these commands you expect a response - usually a specific response particular to the given command. If your boss tells you to �work late tonight� she�s expecting you to, well, work late tonight. And if you tell your dog to �sit� you wouldn�t expect him to walk over to Starbucks and buy himself a cappuccino. This same premise applies in Maya: MEL commands are words linked to actions. When you invoke a MEL command by typing it into the Command Line you cause Maya to perform a particular action specific to that command.

      Not every word or series of letters has an action linked to it - put differently: there are a limited number of valid MEL commands. Attempting to type anything but a valid MEL command into the command line will result in an error like the one we saw above. Similarly, if you turned to your friend and told him to �alsdjf!� he�d probably just tell the bartender you'd had enough for the evening.

      So we�ve determined that neither �alsdjf� nor �something� are valid MEL commands - what is? To answer this let�s take look at another piece of MEL-friendly UI: the Script Editor.

      Launch the Script Editor
      Script Editor Error

      The Script Editor can be launched from the button on the lower right hand side of Maya or through the Window > General Editors > Script Editor menu item. First thing you might notice is a log of our initial foray into MEL:

      alsdjf;
      // Error: line 1: Cannot find procedure "alsdjf". //

      In short the exact same information we got from the Command Line and Command Feedback. However if you scan your eyes up a bit you�ll see a few other messages - logs of commands executed earlier in your Maya session. This top half is referred to as the History Pane. And the bottom half is the Input Pane.

      Script Editor Panes

      The Input Pane is simply a bigger, better Command Line - here you can type multiple MEL commands at once divning many lines. Because you can have multiple lines of MEL commands the Enter key resumes its traditional role of inserting a carriage return. To execute a command (i.e. invoke it/issue it/send it to Maya) you have to either hit Ctrl+Enter or use the Enter key found on your numeric keypad. Once you execute commands in the Input Pane they disappear and move up to the History Pane - to keep them in the Input Pane simply select the commands before executing them.