MayaMEL
From DigitalBlacksmith
Contents |
[edit] Using MEL and Python with Maya 8.0
[edit] MEL
[edit] GUI
http://www.robthebloke.org/mel/GUI_dialogs.html
[edit] Commands and Syntax
[edit] References
Maya MEL Functional Command List
[edit] Coding Tips and Pitfalls
Here are some commands and techniques I've learned the hard way..
[edit] getAttr
I am having a hard time with the getAttr command when more than one attribute matches:
getAttr polySurfaceShape39.do.ovs //Result: 1 1 1 1 1 1 1 //
This matches 7 items in the CDA base
Need to fully qualify the shape:
getAttr stabSwStub4|polySurfaceShape39.do.ovs //Result: 1//
So I need to tweak the script accordingly
[edit] Maya Type Checking
Sometimes MEL commands will return mixed types -- you look at the command sytnax and it says it will return an array of integers (int[]) -- but, in some instances the command will return nothing, an error message, or an exception and your code will crash.
It would be nice if MEL was looseley typed (like PERL, PHP) -- put it's not.
You might get errors like this:
Cannot convert data of type int[] to type int. //
or
Cannot convert data of type string to type int[]. //
To sidestep this, you can use MEL's catch command -- this will essentially try a command, and if there is an error it will continue AND print the error message. Again, the error message is still printed but the program will continue to be interpreted.
Here's how to do it:
int $result = 0;
if( catch( <some line of code here - see example below>)) {
print("Caught an error..but continuing...error message in output is FYI");
$result = 1;
} else {
$result = 0;
}
//Use the $result variable to branch accordingly
Example - The following example tests if a node in the Maya scene is a pure 'group' node -- that is, it has no mesh data, but simply combines lower nodes.
Originally, this check would crash if there was no mesh/triangles for a node:
int $polycount[]; $polycount = `polyEvaluate -v $meshname`;
For mesh nodes, the polyEvalute command will return an integer array. But for empty nodes, it returns an error message string.
The following demonstrates how to sidestep with catch:
/*****************************************************************************
*
* Returns true (1) if the node is simply a grouping node
*
*******************************************************************************/
proc int isGroupNode(string $meshname) {
//debug_str("Checking for group " + $meshname);
int $result = 0;
int $polycount[];
if( catch( $polycount = `polyEvaluate -v $meshname`)) {
//debug_str("FOUND A GROUP!!!");
$result = 1;
} else {
$result = 0;
}
return $result;
}
[edit] Mapy -- WARNING: SPYWARE
I though I found a neat tool called Mapy that let you use a remote editor to run Maya MEL --
But it installed some pretty bad malware (virus) that took over my clip board.
Don't use it.
Mapy = Malware = Virus
[edit] Reloading a Script
Open the script editor in Maya
Verify the script is loaded..In the bottom half of the editor type:
whatIs myscript;
And hit CTRL-ENTER
This should list the full path of the script.
To reload, type the following in the lower half of the window:
source myscript;
You can also make good use of the Maya shell:
Window->General Editors->Command Shell
This will open a shell where you can use history, etc like bash
[edit] UltraEdit Syntax Highlighting
http://www.highend3d.com/maya/downloads/tools/syntax_scripting/1133.html
1. Get the highlight plugin here.
2. Cut and paste the plugin text into your UltraEdit wordfile.txt file. Mine is here:
C:\Program Files\IDM Computer Solutions\UltraEdit-32
3. Restart UltraEdit
[edit] Useful MEL scripts
http://www.johnlomax.com/mel.htm
[edit] Python : An alternative to MEL
And..hehe...Python is supported as of Maya 8 so you don't have to rely on MEL:
