Skip to content

Instantly share code, notes, and snippets.

//all procedures require writeToTextFileAndOpen() proc @ https://gist.github.com/berniebernie/c493e1d13a8aa5a4f161
//
// 1) output translate, rotate, scale for the current frame to a text file
//
$file = "";
$file += "\n\n//==========EDIT AND PASTE IN THE SCRIPT EDITOR ===========================================================\n\n\n";
for($o in `ls -sl -l`){
@berniebernie
berniebernie / MEL: Crossplatform text write and view with notepad.mel.c
Created December 30, 2015 15:37
Function that allows to write text to a temp location (set by maya's internalVar -userTempDir) or a given file, then opens it in a notepad (Notepad for Win, Gedit for linux, and TextEdit for macos)
proc writeToTextFileAndOpen(string $textToWrite, string $fileLocation, int $openAfterWriting){
//cross platform write to textfile or temp textfile
string $tmpfile = "";
if($fileLocation == ""){
string $file = `file -q -sn -shn`;
int $r = `rand 1000 10000`;
$file = ($file=="")?"tmp_maya_file."+$r+".txt":$file+"."+$r+".txt";
string $myScriptDir = `internalVar -utd`;
$tmpfile = $myScriptDir+$file;
@berniebernie
berniebernie / MEL: Display all maya icons.mel.c
Created December 30, 2015 15:10
Shows a window with all icon ressources, more accessible than scrolling through the icons in the shelf options http://i.imgur.com/0WSBD90.png
if (`window -exists AllIconsWin`) deleteUI AllIconsWin;
if (`windowPref -exists AllIconsWin`) windowPref -remove AllIconsWin;
string $window = `window -title "All icons" -rtf 1 -widthHeight 840 550 AllIconsWin`;
columnLayout -adj 1;
$labels = `textFieldGrp -label "Resources: " -text "click icons to get icon names"`;
$scrollLayout = `scrollLayout -verticalScrollBarThickness 16 -h 500`;
rowColumnLayout -numberOfColumns 25;
string $icons[] = `resourceManager -nameFilter "*"`;
@berniebernie
berniebernie / MEL: Incremental save with prompt.mel.c
Last active October 19, 2015 22:29
saves incrementally with a padding of 2, prompts for the name http://i.imgur.com/2GeQRpR.jpg
proc incrementAndSave(){
//takes the current scene, increments (or adds '01' suffix if none found). Padding set to 2
//so many regexes because I suck at this
string $path = `file -q -loc`;
$path = `match "^.*/" $path`;
string $file = `file -q -sn -shn`;
$ext = fileExtension($file);
$file = `match "^[^\.]*" $file`;
string $suffix = `match "[0-9]+$" $file`;
$file = `match ".*[^0-9]" $file`;
@berniebernie
berniebernie / MEL: Select by similar shells.mel.c
Created July 20, 2015 14:18
Methods of non-standard selection of objects and poly faces. Mileage may vary on complex meshes. http://i.imgur.com/ma38hQc.jpg http://i.imgur.com/rfskawS.jpg
//not tested on really heavy meshes
//
//selects shells with same number of faces
//expects 1 shell to be selected in face mode
//change numberOfTests according to mesh density
int $numberOfTests = 5000; //change according to mesh density and distribution, this took approx 10s on a 25k poly object
int $useMoreThanFacesCount = 1; //change to 1 if you want to match using UVs/edge, can be nice if you have same poly count but different UVs/edges count
int $debug = 0;
@berniebernie
berniebernie / MEL: Grow-select faces with angle threshold.mel.c
Last active August 29, 2015 14:25
Grows your selection of faces up to a certain angle threshold. /!\ Slow as fuck http://i.imgur.com/ZTJDrXB.gif
global string $selectedFace;
string $selected[] = `ls -sl`;
$selectedFace = $selected[0];
string $window = `window -title "Select similar faces"`;
columnLayout;
floatSliderGrp -label "Angle threshold " -field true
-minValue 0 -maxValue 180
-cc "growSel"
@berniebernie
berniebernie / MEL: hide objects with balls.mel.c
Last active August 29, 2015 14:25
Hide objects that are outside of control spheres http://i.imgur.com/MtcyybR.gif
/* usage:
run script, select objects to be hidden, press "Select Objects to be hidden" =)
then create and select spheres that will serve as control objects and "Select balls to control"
you can add/remove spheres and objects afterwards by adding remove from the two sets 'objs' and 'control'
slightly buggy because of setAttr in expressions
*/
global string $objs;
@berniebernie
berniebernie / MEL: add edge loops.mel.c
Last active August 29, 2015 14:25
Add edge loops from single selected rings edges http://i.imgur.com/PiVJ350.gif
string $singleEdges[] = {};
string $sel[] = `ls -sl -fl`;
for($o in $sel){
select -r $o;
SelectEdgeRingSp;
polySplitRing -ch 0;
string $sel2[] = `ls -sl -fl -hd 1`;
$singleEdges[size($singleEdges)] = $sel2[0];
}