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

By default any MEL command you invoke, and many of the commands Maya automatically invokes, will be added to the History Pane. As such it is a great way to find out what Maya�s doing �under the hood� and, more importantly, how you can do the same. If you�ve just launched Maya there probably isn�t much going on in the History Pane at the moment. But even at it�s barest you can find a couple examples of real live MEL commands:

Script Editor Startup

Both �file -f -new� and �docServer -start� are valid MEL commands. Technically only �file� and �docServer� are commands, the dash-y things following them are called �command flags� - we�ll get into that later. For now select �file -f -new;� and copy (Ctrl+C) paste (Ctrl+V) it into the Input Pane. Are you ready? .... Okay let�s execute! Hit Ctrl+Enter and let her rip! ...

... I know it may not look like much happened, but, without opening up the File Menu, without hitting the little axes button thing New Scene Buttonyou created a new scene. Give it another go - create some spheres and cones, and then execute �file -f -new� again ... ... Neat, eh? And the excitement doesn�t stop there - oh no, we�re just getting started. Let�s see what else we can do with a little help from our friends Messieurs History and Input Pane.


Grabbing Output and Reusing


It One of MEL�s most hyped virtues is its ability to �automate repetitive workflows� - in fact you�ll see that phrase used almost word for word in countless tutorials and articles (and you�ll note that this one is no different). A fair question might be �So, how exactly can I use MEL to automate repetitive workflows?� - to which someone might respond �Well first you do your workflow and then you use MEL to automate it.� Surprisingly this glib answer isn�t that far off base. Let�s start with a workflow I�m sure everyone is dying to automate: creating a sphere - if we�re lucky we may even have time to move it and scale it a bit. Create a poly sphere by going to theCreate > Poly Primitives > Sphere menu item. If you look back at the History Pane you should see two new lines:
 
Create Sphere

polySphere -r 1 -sx 20 -sy 20 -ax 0 1 0 -tx 2 -ch 1;
// Result: pSphere1 polySphere1 //

The first line is a valid MEL command, and the second is a �comment�. We�ll get into comments in the next article, but for now it�s enough to know that they are completely ignored by Maya. You can execute it or not, it won�t make a difference.  Like before you could copy and paste these lines to the Input Pane, execute them, and create yourself another sphere. Instead try moving the sphere somewhere new and scaling it up a bit. You should now have something like this in your History Pane


Moved Sphere

In my case three more lines have been added:

move -r 0 0 -1.941666 ;
move -r 0 1.192061 0 ;
scale -r 0.540501 0.540501 0.540501 ;

Each of these lines starts with a word followed by some letters and numbers. The word, as we�ve seen before, is a MEL command - the letters and numbers are MEL flags and flag arguments respectively. We�ll get to those a bit later. The first two lines starting with �move� are, surprisingly, the MEL commands used to move the sphere back and up a bit. The last line, �scale�, is the MEL command to scale the sphere smaller. If you�ll humor me a bit and allow me to call this a �workflow�, we�ll move to the next step: using MEL to automate it.

Just to make sure it still works, copy and paste those five lines into the Input Pane and execute them ... ... If all went well you should now have two moved and scaled spheres, one on top of the other. Technically speaking, we�ve just automated that workflow. However, all that cutting and pasting stuff is not nearly as swanky as, say, a button on some sort of shelf like UI. Well, my friend, are you in luck today cause Maya comes complete with not only the world�s best sphere mover and scaler, but also your very own shelf buttons! To tap into the power of the shelf simply select those five lines from the History Pane and, using your middle mouse button, drag the selection onto the Shelf.

Drag And Drop

A new button should appear that looks like this:

New Shelf Button

Every time you click that button the selected MEL commands will be run. The point of all this is to show how easy it is to capture, save, and replay pretty much anything you do in Maya - you don�t need to write a single line of MEL from scratch. Next time you create a skeleton or import a prop file, take a look at the History Pane - maybe there�s something there you can save and reuse.