Maya Scripts
applyClothPresetToMultiple.mel was used in the gif.
Some MEL and Python scripts to improve daily tasks in Maya.
sortByPolyCount.py
Add to maya shelf, make a selection, click.
Console will print the name and poly counts of the heaviest objects.
You can then easily isolate the selection (ctrl+1), or keep the selection in the layer it creates.
def sortByPolyCount(top, layer): objects = cmds.ls( selection=True ) tri_list = {} for object in objects: cmds.select(object) tri_count = cmds.polyEvaluate( t=True ) tri_list[object] = tri_count sorted_names = sorted(tri_list, key=tri_list.__getitem__, reverse=True) for name in sorted_names[:top]: print("{} : {}".format(name, tri_list[name])) if(layer): cmds.select(sorted_names[:top]) cmds.createDisplayLayer(name='top') else: cmds.select(sorted_names[:top]) return tri_list sortByPolyCount(5, True)
applyClothPresetToMultiple.mel
Add to maya shelf, make a selection, click.
This script will apply a saved nCloth preset to all selected cloths.
You will need to replace “inflate1” in the code to the name of your preset.
//select all cloths and run //to apply same preset to all string $cloths[] = `ls -sl`; for ($cloth in $cloths){ select $cloth; string $clothShape[] = `listRelatives -s `; print $clothShape[0]; select -r $clothShape[0]; applyPresetToNode $clothShape[0] "" "" "inflate1" 1; //dynExpression -s ($clothShape[0]+".pumpRate = rand(0.5, 1.25);") -rbd $clothShape[0]; }
setAiOpaqueMultiple.py
Add to maya shelf, make a selection, click.
This script will set the ‘aiOpaque’ property to false on all selected.
This is useful when you have several objects that all need to be rendered as transparent in Arnold.
import maya.cmds as cmds objects = cmds.ls( selection=True ) for object in objects: cmds.setAttr(object + ".aiOpaque", 0)
seanSplicer.mel
Add to maya shelf, click.
This script will slice n’ dice models.
// create a GUI window -title "Sean Splicer" -menuBar true -width 100; // add a help menu menu -label "Help" -helpMenu true; menuItem -label "About Application..."; // create a pane layout to holds the info paneLayout -configuration "horizontal2"; // create 4 scroll fields scrollField -wordWrap true -text "Select object you wish to chop up. %Values are relative to object size." -editable false; // add the other controls columnLayout; floatSliderGrp -label "Chunk Height %" -field true -pre 2 -minValue 0.05 -maxValue 100 -value 2 chunkSlider; floatSliderGrp -label "Gap Height %" -field true -minValue 1 -maxValue 99 -value 1 gapSlider; intSliderGrp -label "Cut width %" -field true -minValue 1 -maxValue 100 -value 100 widthSlider; intSliderGrp -label "Cut depth %" -field true -minValue 1 -maxValue 100 -value 100 depthSlider; button -command ("seanSplicer()") -label "chop it up fam"; showWindow; proc seanSplicer(){ //store name of mesh to splice string $OG[] = `ls -sl`; select -r $OG[0]; if(size(listRelatives("-parent"))){ parent -w; } DeleteHistory; makeIdentity -apply true -t 1 -r 1 -s 1 -n 0 -pn 1; float $minY = `getAttr ($OG[0] + ".boundingBoxMinY")`; float $maxY = `getAttr ($OG[0] + ".boundingBoxMaxY")`; float $objHeight = $maxY - $minY; float $objWidth = `getAttr ($OG[0] + ".boundingBoxMaxX")` - `getAttr ($OG[0] + ".boundingBoxMinX")`; float $depth = `getAttr ($OG[0] + ".boundingBoxMaxZ")` - `getAttr ($OG[0] + ".boundingBoxMinZ")` + 1; int $i; float $chunkHeight = (`floatSliderGrp -q -value chunkSlider` * 0.01) * $objHeight; float $gapHeight = (`floatSliderGrp -q -value gapSlider` * 0.01) * $objHeight; float $gapWidth = ((`intSliderGrp -q -value widthSlider`) * 0.01) * $objWidth; float $gapDepth = (( 1 - (`intSliderGrp -q -value depthSlider`)) * 0.01) * $depth; float $startY = $minY; //center pivot of object first xform -cp $OG[0]; float $centerX = `objectCenter -x $OG[0]`; float $centerZ = `objectCenter -z $OG[0]`; for ($i = 0; $i < ($objHeight / ($chunkHeight + $gapHeight)); $i++) { polyCube -w $gapWidth -h $gapHeight -d $depth -sx 1 -sy 1 -sz 1 -ax 0 1 0 -cuv 4 -ch 1 ; rename spliceCube[$i]; move -r -os -wd $centerX $startY $centerZ; $startY += $chunkHeight + $gapHeight; } string $myCubes[] = `ls -type shape "spliceCube*"`; select $myCubes; if(`intSliderGrp -q -value depthSlider` != 100){ move -r -os -wd 0 0 ($depth + $gapDepth); } //merge all cubes string $merged = "mergedSplice"; polyUnite -ch 1 -mergeUVSets 1 -name $merged; DeleteHistory; //align cubes to center of object select $merged ; select -tgl $OG[0] ; align -atl -x Mid -y Mid; select $OG[0]; select -tgl $merged; DeleteHistory; PolygonBooleanDifference; DeleteHistory; }