Created
September 10, 2017 10:04
-
-
Save bitinn/10b2cbbee630142fc99a25cb8e350731 to your computer and use it in GitHub Desktop.
MEL Template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Script Name: Basic Template | |
// | |
// 2017 David Frank / Public Domain | |
// | |
/* | |
Helper procedures | |
makes maya MEL life easier | |
(they should be atomic and not rely on other procedures) | |
*/ | |
// get maya version as int | |
proc int GetMayaVersion () { | |
string $Version = `about -version`; | |
return ((int) $Version); | |
} | |
// check LT variant | |
proc int IsMayaLT () { | |
return ((int) `about -ltVersion`); | |
} | |
// nprint - just print() with a newline appended | |
proc nprint (string $Message) { | |
print($Message + "\n"); | |
} | |
// nwarning - just warning() without context blocking the message | |
proc nwarning (string $Message) { | |
if (catchQuiet(`warning -noContext $Message`)) { | |
warning $Message; | |
} | |
} | |
// nerror - just error() without context blocking the message | |
proc nerror (string $Message) { | |
if (catchQuiet(`error -noContext $Message`)) { | |
error $Message; | |
} | |
} | |
/* | |
Global constants | |
due to lack of constants and serious global pollution in MEL, | |
we use procedure to represent constant values. | |
(use UPPER_SNAKE_CASE to signal them) | |
*/ | |
// script directory (use custom folder instead of root folder) | |
proc string SCRIPT_DIR () { | |
return `internalVar -userScriptDir` + "YourFolderName/"; | |
} | |
/* | |
Local procedures | |
(most of the work should be in this section) | |
*/ | |
/* | |
LocalProcedure - a simple demo of local proc | |
input: | |
- $Message / string / input | |
return: | |
- string / output | |
*/ | |
proc string LocalProcedure (string $Message) { | |
return $Message + " world"; | |
} | |
/* | |
Global procedures | |
they can be called in script editor, or bind as shelf buttons | |
(use proper prefix to avoid name collision) | |
*/ | |
/* | |
YOURPREFIX_GlobalProcedure - a simple demo of global proc | |
input: none | |
return: none | |
*/ | |
global proc YOURPREFIX_GlobalProcedure () { | |
nprint(LocalProcedure("hello")); | |
} | |
/* | |
Default procedure | |
this is invoked when you source the script. | |
(comment it out if it's not the default behaviour you want) | |
*/ | |
YOURPREFIX_GlobalProcedure(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment