« Tabbed Layouts in Maya Embedded Language - Part 2 | Main | Mobile Development: Apps vs. Games »
Friday
Aug272010

Tabbed Layouts in Maya Embedded Language - Part 1

Maya Embedded Language (MEL) is included with every license of Autodesk Maya.  MEL is an powerful scripting language that allows the user to automate nearly any task of which Maya is capable.  If you find yourself doing the same task over and over, it is probably time to create a tool using MEL. 

There are several books on MEL available, and I won’t attempt to recreate what those authors have done.  What I will cover is one aspect of user interface (UI) creation in MEL - Tab Layouts.

Creating effective UI in MEL is one the most difficult challenges in writing MEL scripts.  You won’t find any drag and drop editors in Maya.  Every control and layout option must be written in MEL.  The results are well worth the effort though, because without proper formatting, a MEL interface can difficult to use.

To prevent this, a wide variety of UI options that you can use.  One of the most useful is the Tab layout.  Tab layouts in MEL look like tab layouts in any other program, and work accordingly.  By using tabs to organize your controls into related groups, you make it easier for you or someone else to understand the flow of you script.

NOTE:

  • This tutorial assumes that you have used the Script Editor before, and have written at least one or two MEL scripts.
  • All code snippets will be placed in separate text boxes.  Each one will be a complete, functioning piece of code.  To see them work, copy and paste the code from this page, to the Script Editor in Maya.

     

Before creating our tab layout, we’re going to create a shelf button to solve a common problem in testing MEL scripts.

Here’s the problem:

Clicking on the close button at the top of the window, does not remove the window from memory.  If you try to run a script with the same window object, you will receive and error message and your script will not run.  To remove the window from memory, you must use the “deleteUI” command instead.

 Here’s the solution:

We’re will create a shelf button that will close the window, and remove it from memory.

 

To create a shelf button for deleteUI, do the following:

  • Start Maya.
  • Click on the Script Editor button to open it.
  • In the input pane (lower pane), type in the following text:

deleteUI -window “myWindow”

 

  • Highlight the text you just typed.
  • In the File menu in the Script Editor (not the main Maya window), select Save Script to Shelf.
  •  

    You will be prompted to name the button.  Enter something that makes sense to you.  I chose to name it “delUI”.  NOTE: you only have space for four or five characters on the button, so keep the name short.

    In Part 2, you will build the basic window in which all of your controls will be placed.

    PrintView Printer Friendly Version

    EmailEmail Article to Friend