Customization and MEL Scripting AL MAYA TAKES THE lion’s share of high-end 3D work in the feature film and visual effects industry. You can trace this fact to one particular trait: the software is infinitely customizable. The customization is not restricted to multimillion-dollar productions, however. You can customize Maya to your own tastes and thereby work faster, more intelligently, and most important, more comfortably.
Chapter 1 Customization and MEL Scripting a Resetting to Factory/Swapping Prefs Files There comes a time in every animator’s life when it’d be nice to return to the past. That is, it’s sometimes necessary to return Maya to either its “factory default” or to a state that is known to be productive. To return the Maya user interface (UI) and global preferences to the factory default, choose Window ➔ Settings/Preferences ➔ Preferences.
Resetting to Factory/Swapping Prefs Files shelves A folder that contains default and custom shelves. Each shelf is saved as a file (for example, shelf_Animation.mel). This folder is empty until a custom shelf is saved or Maya is exited for the first time. The following files are created or updated when Maya is exited or the Save button is clicked in the Preferences window: userHotkeys.mel Lists user-defined hot keys. userNamedCommands.mel Lists commands that have user-defined hot keys assigned to them.
Chapter 1 Customization and MEL Scripting If need be, you can edit any of the files in the prefs folder with a text editor. Perhaps the most useful file to edit by hand is userRunTimeCommands.mel, in which it’s easy to delete custom commands that are no longer needed. You can force Maya to update the files in the prefs folder by executing the savePrefs command in the Script Editor. The savePrefs command offers various flags, such as -uiLayout, that allow you to update specific files.
Building a Simple MEL Window Editor. To do this, highlight the shelf name in the Shelves tab, select the icon name in the Shelf Contents tab, and make your changes in the Edit Commands tab. If you want to save your changes, press the keypad Enter key. To save all the shelves, click the Save All Shelves button (this exits the window). The Edit Commands tab of the You can customize the look of a shelf icon by entering Shelf Editor window a name into the Icon Name field.
Chapter 1 Customization and MEL Scripting This script is saved as simple.mel in the Chapter 1 mel folder on the CD. To use it, open the Script Editor, choose File ➔ Source Script, and browse for the file. The MEL window pops up immediately. You can also paste the text into the work area of the Script Editor, highlight it, and MMB drag it onto a shelf to create a shelf icon. You’re free to use any command within the quotes after each -command flag, whether it is used for a menu item or a button.
Building an Intermediate MEL Window On the first line of the script, the window command describes the GUI window. On the last line, showWindow newWindow launches the described window. A variation of the window command is mandatory if a pop-up window is desired. If you write a new MEL script, or adapt an example, and the script fails to run, a red error message appears on the Command line. (Top) A red MEL error on the Command line. (Bottom) A MEL error message in the Script Editor.
Chapter 1 Customization and MEL Scripting determined by a closing curly bracket }. In the case of newcam.mel, the closing curly bracket is on the last line of the script. A procedure is not activated until it is called. Executing the procedure name in the Script Editor work area is one way to call a procedure. This assumes that the procedure is global, which is determined by the inclusion of the word global.
Creating an Autosave MEL Script The intField command creates an integer field. The -width flag sets the field width in pixels. The -value flag sets a default value that appears in the field. -minValue and -maxValue flags set lower and upper field limits. The -changeCommand flag executes a command when the value in the field is changed (and the Enter key is pressed).
Chapter 1 Customization and MEL Scripting scriptJob “triggers” a command when a particular event occurs. If the event does not occur, no action is taken. The easiest way to apply scriptJob is with the following line: scriptJob -event “event_name” “command”; The -event flag offers a long list of events to choose from. Perhaps the most useful is “SelectionChanged”, which triggers the command any time any object in Maya is selected or deselected.
Creating Your Own Paint Effects Brushes A working autosave script, named as.mel, is included in the Chapter 1 mel folder on the CD. To use as.mel, choose File ➔ Source Script in the Script Editor. By default, it will pop up a save reminder window every 5 minutes. With this script, you have the option to save the file with an incremental name (as.1.mb, as.2.mb, and so on), skip the save and exit the window, or kill the autosave job completely.
Chapter 1 Customization and MEL Scripting 2. Select the stroke curve and open its Attribute Editor tab. Switch to the Paint Effects tab to the immediate right of the stroke tab. The Paint Effects tab is named after the brush type. In the Texturing section, click the file browse button beside the Image Name attribute and load your own bitmap. IFF, TIF, and BMP formats work. If you’d like transparency, choose an IFF file with an alpha channel.
Creating Your Own Paint Effects Brushes The result of a custom Paint Effects sprite brush. The brush is included as MayaBrush.mel in the Chapter 1 mel folder. Customizing a Tube Brush The main disadvantage of sprite brushes is the two-dimensionality of the resulting stroke. In addition, sprite strokes tend to create poor shadows. Tube strokes, on the other hand, can be quite realistic. Tube brushes are easily adapted with the Paint Effects Brush Settings window.
Chapter 1 Customization and MEL Scripting It’s possible to adapt the MEL script of a tube brush, although it’s a bit more tricky. As an example, the first line of the willow.mel brush, found in the trees brush folder, looks like this: brushPresetSetup();bPset “time” 1; bPset “globalScale” 0.3186736972; bPset “depth” 1; bPset “modifyDepth” 1;... This is only a small portion of the first line. If printed out in full, it would fill an entire page. Fortunately, you can decipher it.
Creating Notes for Your Fellow Animators An annotation note and its position within the Hypergraph Hierarchy window The annotation node is parented to a locator, which in turn is parented to the object. In reality, the arrow has a desire to point toward the locator. The annotation and locator nodes can be unparented and “freed” from the object or simply deleted if no longer needed. You can update the text at any time by opening the annotation node’s Attribute Editor tab.
Chapter 1 Customization and MEL Scripting a Passing Information to Files Maya allows you to write and read custom binary files. This is useful when a MEL script needs to call on a list or if the script needs to permanently record events (for example, a dynamic simulation). To write to a file, you can use this code: $fileName = ( `internalVar -userWorkspaceDir` + “note.
Passing Information to Files directory path is declared, Maya assumes that note.tmp resides in the project directory. The $valueToWrite string is constructed from the variable $test, which is defined outside the procedure, and “\n”. The \n instructs fprint to include an end-of-line code. This forces fprint to create a brand-new line the next time the procedure is called. If \n is not used, fprint will continually append to the same line.
Chapter 1 Customization and MEL Scripting With this code, the Windows command type prints out the contents of note.txt, which is found in the same folder as the script. The contents are “captured” by the popen command and made available for fgetline to read. $lineNumber establishes how many lines the text file contains. Each line is temporarily stored by the $line variable, allowing it to be printed with the print command. As an additional working example, a MEL script named video.
Industry Tip: Creating an “Expert Mode” MEL Script (Top) Maya interface with all UI elements hidden appears in monitor 1. (Bottom) MDMwindow.mel window fills monitor 2.
Chapter 1 Customization and MEL Scripting Imbedded shelf buttons Shelf buttons are freed from shelves and integrated directly into the layout. To create a single shelf button with a custom icon that creates a NURBS circle, the following line is used: shelfButton -image1 “MDMcircleY.bmp” -width 32 -height 32 -c CreateNURBSCircle; Maya assumes that the custom icon BMP file is in the default icons folder. For example, the path might be as follows: C:\Program Files\Alias\Maya8.
Industry Tip: Creating an “Expert Mode” MEL Script MICHAEL STOLWORTHY After graduating with a degree in Media Arts and Animation, Michael served as creative director at Concept Design Productions, Inc., in Pasadena, California. Concept Design Productions specializes in the creation of retail store space, stage sets, trade show exhibits, and themed environments for public relations events. He has recently joined GES in Las Vegas, Nevada, as an exhibit designer.