Last active
October 15, 2021 15:15
-
-
Save plasticarm/b4a2afa1775203567056f005ff23e7ce to your computer and use it in GitHub Desktop.
Snippets for Maya Mel
This file contains 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
/*SEARCH STRING : | |
<ToDoWiz!> : Put this tag for an important reminder | |
<ToDo> : Put this tag for a reminder to do something | |
<!PROBLEM!> : Put this tag for a reminder of what a problem in the code is | |
@ : Put this in front of a important functions | |
# : Put this in front of ui functions | |
*/ | |
//<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> | |
//|||||||||||||||||||||||||:::WIZ:::|||||||||||||||||||||||||||||||||| | |
//<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> | |
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | |
// NAME WIZ | |
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | |
//<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> | |
/*==================================================================== | |
Author: | |
Email: | |
Website: | |
---------------------------------------------------------- | |
Summary: | |
====================================================================*/ | |
[-] : A generic message | |
[+] : Something was just added to the scene | |
[!] : A problematic issue occured | |
[#] : Something that should be monitored for accuracy | |
[@] : A function was started | |
[*] : The folling text is a command that was processed | |
[:] : A name should be checked for issues | |
*/ | |
/* | |
F0NTS: | |
Courier New | |
Microsoft JhengHei UI | |
MS Gothic | |
Adobe Heitie | |
Proggy Clean | |
*/ | |
//==================================================================== | |
// GLOBAL VARS | |
//==================================================================== | |
//======================================================================================================== | |
//[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][] | |
/////////////////// ///////////////////////////////////////////////////////////////////// | |
// WINDOWS | |
/////////////////// ///////////////////////////////////////////////////////////////////// | |
//[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][] | |
//======================================================================================================== | |
//======================================================================================================== | |
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | |
/////////////////// ///////////////////////////////////////////////////////////////////// | |
// LAYOUTS | |
/////////////////// ///////////////////////////////////////////////////////////////////// | |
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | |
//======================================================================================================== | |
//------------------------------------------------------- | |
//[][][][][][][][][][][][]<FRAME>[][][][][][][][][][][][] | |
//][][][][][][][][][][][<END-FRAME>][][][][][][][][][][][ | |
//------------------------------------------------------- | |
//------------------------------------------------------- | |
//|||||||||||||||||||||||<COLUMN>|||||||||||||||||||||||| | |
//|||||||||||||||||||||<END-COLUMN>|||||||||||||||||||||| | |
//------------------------------------------------------- | |
//------------------------------------------------------- | |
//========================<ROW>========================== | |
//======================<END-ROW>======================== | |
//------------------------------------------------------- | |
//------------------------------------------------------- | |
//########################<TAB>########################## | |
//######################<END-TAB>######################## | |
//------------------------------------------------------- | |
//======================================================================================================== | |
//"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
/////////////////// ///////////////////////////////////////////////////////////////////// | |
// MENUS | |
/////////////////// ///////////////////////////////////////////////////////////////////// | |
//"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
//======================================================================================================== | |
//------------------------------------------------------- | |
//_-_-_-_-_-_-_-_-_-_-_-_<MENUBAR>_-_-_-_-_-_-_-_-_-_-_-_ | |
//_-_-_-_-_-_-_-_-_-_-_<END-MENUBAR>-_-_-_-_-_-_-_-_-_-_- | |
//------------------------------------------------------- | |
//------------------------------------------------------- | |
//-=-=-=-=-=-=-=-=-=-=-=<SUB-MENU>=-=-=-=-=-=-=-=-=-=-=-= | |
//-=-=-=-=-=-=-=-=-=-=<END-SUB-MENU<=-=-=-=-=-=-=-=-=-=-= | |
//------------------------------------------------------- | |
//======================================================================================================== | |
//######################################################################################################## | |
//******************************************************************************************************** | |
/////////////////// ///////////////////////////////////////////////////////////////////// | |
// FUNCTIONS | |
/////////////////// ///////////////////////////////////////////////////////////////////// | |
//******************************************************************************************************** | |
//######################################################################################################## | |
//======================================================================================================== | |
//======================================================================================================== | |
//<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> | |
/////////////////// ////////////////////////////////////////////////////// | |
// SECTION HEADER | |
/////////////////// ////////////////////////////////////////////////////// | |
//<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> | |
//======================================================================================================== | |
//======================================================================================================== | |
//******************************************************************************************************** | |
//******************************************************************************************************** | |
//******************************************************************************************************** | |
//======================================================================================================== | |
//<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> | |
/////////////////// ////////////////////////////////////////////////////// | |
// SUPER SECTION HEADER | |
/////////////////// ////////////////////////////////////////////////////// | |
//<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> | |
//======================================================================================================== | |
//******************************************************************************************************** | |
//******************************************************************************************************** | |
//******************************************************************************************************** | |
//======================================================================================================== | |
//-------------------------------------------------------------------- | |
////////////////////////////////////////////////////////////////////// | |
// SUB SECTION HEADER | |
////////////////////////////////////////////////////////////////////// | |
//-------------------------------------------------------------------- | |
/*======================| SUMMARY |=================================== | |
/*=======================| USAGE |==================================== | |
====================================================================*/ | |
/*----------------------| SUMMARY |----------------------------------- | |
/*----------------------| USAGE |------------------------------------- | |
--------------------------------------------------------------------*/ | |
//******************************************************************** | |
// IMPORTANT NOTE | |
//******************************************************************** | |
/************ IMPORTANT ********************************************** | |
*********************************************************************/ | |
/*############ PROBLEM ############################################### | |
####################################################################*/ | |
//_________________________________________ | |
// Section Of Function | |
//@ | |
//======================================================= | |
//@ GENERIC PROCEDURES | |
//======================================================= | |
/*****************************************************************//** | |
* Brief description. | |
* More information. | |
* USAGE : | |
* | |
*********************************************************************/ | |
/*======================| SUMMARY |===============================//** | |
* Brief description. | |
* Detailed description. | |
* | |
* | |
* | |
* | |
* | |
====================================================================*/ | |
global proc someProcName() | |
{ | |
string $sel[] = `ls -sl`; | |
//FOR LOOP | |
for ($i=0;$i<`size $sel`;$i++){ | |
} | |
} | |
//@ PROC NAME | |
//==================================================================== | |
/*****************************************************************//** | |
Brief description. | |
<hr> | |
<b>Synopsis</b><br> | |
procName [-fa string] [-fb linear] <br> | |
A more detailed description. | |
<b>Return value</b><br> | |
string[] description of return. | |
<b>Flags</b><br> | |
-fa, -fb | |
<hr> | |
<b>Related</b><br> | |
someProcedure(), | |
<b>Examples</b><br> | |
<code> | |
string $arr[] = procName("-fa aString -fb anotherString"); | |
</code> | |
*********************************************************************/ | |
global proc string[] someProcedure( string $flags ) | |
{ | |
string $tok[] = tokenizeString($flags, " "); | |
for ($i=0;$i<`size $tok`;$i++){ | |
switch ($tok[$i]){ | |
case "-stringTag" : case "-t" : | |
string $thisFlag = $tok[($i + 1)]; | |
break; | |
case "-intTag" : case "-it" : | |
int $iT = int($tok[($i + 1)]); | |
break; | |
case "-tx" : case "-text" : | |
$rcommand = wizFlagString($tok, $i); | |
break ; | |
} | |
} | |
return {""}; | |
} | |
//><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>< | |
//TOKENIZE STRING | |
//------------------------------------------- | |
global proc string[] tokenizeString(string $string, string $sep) | |
{ | |
string $buffer[]; | |
int $numTok = `tokenize $string $sep $buffer`; | |
return $buffer; | |
} | |
global proc string wizFlagString( string $arr[], int $start ) | |
{ | |
// just make sure that the start index isn't a flag | |
if (startsWith($arr[$start], "-")){ | |
$start++; | |
} | |
string $return = getStringFromCurrentIndexToNextTagIndex($arr, $start); | |
return $return; | |
} | |
global proc string getStringFromCurrentIndexToNextTagIndex( string $arr[], int $start) | |
{ | |
string $return[]; | |
int $nextTagIndex = getNextTagIndex($arr, $start); | |
if ($nextTagIndex > ($start + 1)){ | |
$return = copyStringArrayFromIndexToIndexToStringArray($arr, ($start), $nextTagIndex); | |
} else { | |
$return[`size $return`] = $arr[$start]; | |
} | |
string $returnString = stringArrayToString($return, " "); | |
return $returnString; | |
} | |
//COPY STRING ARRAY FROM - TO | |
//----------------------------------- | |
global proc string[] copyStringArrayFromIndexToIndexToStringArray(string $arr[], int $start, int $end) | |
{ | |
string $newArr[]; | |
for($i=$start;$i<$end;$i++){ | |
$newArr[`size $newArr`] = $arr[$i]; | |
} | |
return $newArr; | |
} | |
//** Breif description. */ | |
//@ SUBORDINATE PROCEDURE | |
//------------------------------------------------------- | |
//@ | |
//------------------------------------------------------- | |
global proc string[] someOtherProcName(string $sel[]){ | |
return $sel; | |
} | |
//@ MENU ITEMS | |
//======================================================= | |
menuItem -sm true -l "Some Proc Group"; | |
menuItem -l "Some Proc Name" -c ("passSelectionListToCommandGetReturnSelectionList(" + "\"" + $textScrollList + "\"" + ",\"someProcName\");"); | |
menuItem -l "Another Proc Name" -c ("passSelectionListToCommandGetReturnSelectionList(" + "\"" + $textScrollList + "\"" + ",\"anotherProcName\");"); | |
//MENU OPTION BOX | |
menuItem -ob true -c ("openCurrentOptionsLayout(\"someProcOptionsMenu\");"); | |
setParent -menu..; | |
//@ TEXT | |
//====================================================== | |
wizText("Some text about something"); | |
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | |
////////////////////////////////////////////////////////////////////// | |
// LAYOUTS | |
////////////////////////////////////////////////////////////////////// | |
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | |
//@ A SECTION LAYOUT | |
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | |
global proc aSectionLayout(string $parent) | |
{ | |
string $frameLayout = `frameLayout | |
-l "A Section Layout" | |
-ann "" | |
-bv true | |
-la "center" | |
-li 10 | |
-lv true | |
-mw 10 | |
-mh 10 | |
-cll true | |
-cl true | |
-parent $parent | |
`; | |
//or... | |
string $layout = wizStandardFrameLayoutNoMargins($parent, "Label", "uniqueLayoutName_frameLayout"); | |
switch($mode){ | |
case "modeA" : | |
setAttr "fullDome1.filmTranslateV" 0; | |
break; | |
case "modeB" : | |
setAttr "fullDome1.filmTranslateV" -0.21; | |
break; | |
} | |
string $someCommand = ("string $x = something;" + "\n" | |
+"doSomething();" + "\n"); | |
// Use eval and get a return value. Don't use `; | |
float $tx = `getAttr persp.translateX`; | |
print ("TX : " + $tx + "\n"); | |
float $poop; | |
string $eval = ("getAttr persp.translateX;"); | |
$poop = eval($eval); | |
print ("Poop : " + $poop + "\n"); | |
} | |
//@ PROC NAME | |
//==================================================================== | |
/*================================================================//** | |
Brief Summary. | |
<DT> Synopsis</DT><br> | |
procName [-tag1 string] [-tag2 linear] <br> | |
<b>Return value</b><br> | |
string[] description of return. | |
<b>Flags</b><br> | |
-tag1, -tag2 | |
<b>Example</b><br> | |
string $arr[] = procName($string, 2); | |
====================================================================*/ | |
global proc addSomeAttributes() | |
{ | |
//Boolean | |
if (`attributeExists "boolAttrName" $sel` == 0){ | |
addAttr -ln "boolAttrName" -at bool $sel; | |
setAttr -e -keyable true ($sel + ".boolAttrName"); | |
setAttr ($sel + ".boolAttrName") true; | |
} | |
//String | |
if (`attributeExists "stringAttrName" $sel` == 0){ | |
addAttr -ln "stringAttrName" -dt "string" $sel; | |
setAttr -e -keyable true ($sel + ".stringAttrName"); | |
setAttr -type "string" ($sel + ".stringAttrName") "something"; | |
} | |
//Enum | |
if (`attributeExists "enumAttrName" $sel` == 0){ | |
addAttr -ln "enumAttrName" -at "enum" -en ("typeOne=0:typeTwo=1:typeThree=2:") $sel; | |
setAttr ($sel + ".enumAttrName") 0; | |
} | |
//Int | |
if (`attributeExists "intAttrName" $sel` == 0){ | |
addAttr -ln "intAttrName" -at long -dv 5 $sel; | |
setAttr -e -keyable true ($sel + ".intAttrName"); | |
setAttr ($sel + ".intAttrName") 1; | |
} | |
//Float | |
if (`attributeExists "floatAttrName" $sel` == 0){ | |
addAttr -ln "floatAttrName" -at double -dv 1 $sel; | |
setAttr -e -keyable true ($sel + ".floatAttrName"); | |
setAttr ($sel + ".floatAttrName") 1.245; | |
} | |
//3 Ints | |
if (`attributeExists "threeIntsAttrName" $sel` == 0){ | |
addAttr -ln "threeIntsAttrName" -at short3 $sel; | |
addAttr -ln "threeIntsAttrNameX" -at short -p "threeIntsAttrName" $sel; | |
addAttr -ln "threeIntsAttrNameY" -at short -p "threeIntsAttrName" $sel; | |
addAttr -ln "threeIntsAttrNameZ" -at short -p "threeIntsAttrName" $sel; | |
setAttr ($sel + ".threeIntsAttrName") 0 0 0; | |
} | |
//3 Floats | |
if (`attributeExists "threeFloatsAttrName" $sel` == 0){ | |
addAttr -ln "threeFloatsAttrName" -at float3 $sel; | |
addAttr -ln "threeFloatsAttrNameX" -at "float" -p "threeFloatsAttrName" $sel; | |
addAttr -ln "threeFloatsAttrNameY" -at "float" -p "threeFloatsAttrName" $sel; | |
addAttr -ln "threeFloatsAttrNameZ" -at "float" -p "threeFloatsAttrName" $sel; | |
setAttr ($sel + ".threeFloatsAttrName") 0.0 0.0 0.0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment