/*the MultiSucker was written by Jeff Tiensivu www.JeffTiensivu.com 11/03/2014 */ global proc string[] findMultiSucks() { string $listOfShapes[] = `ls -l -geometry`; int $numShapes = size($listOfShapes); int $whichShape; string $shapeType[]; string $connections[]; int $numConnections; string $listMultiSucks[]; int $numMultiSucks = 0; for ($whichShape = 0; $whichShape < $numShapes; $whichShape++) { $shapeType = `ls -showType $listOfShapes[$whichShape]`; if ($shapeType[1] == "nurbsCurve") //skip curves { continue; } $connections = listShaders($listOfShapes[$whichShape]); $connections = stringArrayRemoveDuplicates($connections); $numConnections = size($connections); if ($numConnections > 1) { $listMultiSucks[size($listMultiSucks)] = $listOfShapes[$whichShape]; } $numMultiSucks = size($listMultiSucks); } return $listMultiSucks; } ///////////////////////////////////////////////////////////////////////////////////////end findMultiSucks global proc string[] findSelectedMultiSucks() { string $listOfSelected[] = `ls -l -sl`; //print $listOfSelected; int $numSelected = size($listOfSelected); string $listOfShapes[]; for ($whichSelected = 0; $whichSelected < $numSelected; $whichSelected++) { string $selectedsChildren[] = `listRelatives -c -s -f $listOfSelected[$whichSelected]`; $listOfShapes = stringArrayCatenate($listOfShapes, $selectedsChildren); } int $numShapes = size($listOfShapes); int $whichShape; string $shapeType[]; string $connections[]; int $numConnections; string $listMultiSucks[]; int $numMultiSucks = 0; for ($whichShape = 0; $whichShape < $numShapes; $whichShape++) { $shapeType = `ls -showType $listOfShapes[$whichShape]`; if ($shapeType[1] == "nurbsCurve") //skip curves { continue; } $connections = listShaders($listOfShapes[$whichShape]); $connections = stringArrayRemoveDuplicates($connections); $numConnections = size($connections); if ($numConnections > 1) { $listMultiSucks[size($listMultiSucks)] = $listOfShapes[$whichShape]; } $numMultiSucks = size($listMultiSucks); } //print ($numMultiSucks + "\n"); //print $listMultiSucks; return $listMultiSucks; } //////////////////////////////////////////////////////////////////////////////////////////end findSelectedMultiSucks global proc string[] listShaders(string $thisObject) { string $connectedShaders[] = `listConnections -d on -s off -type shadingEngine $thisObject`; //$connectedShaders = stringArrayRemoveDuplicates($connectedShaders); string $isg[] = {"initialShadingGroup"}; $connectedShaders = stringArrayRemove($isg, $connectedShaders); return $connectedShaders; } /////////////////////////////////////////////////////////////////////////////////////////////end listShaders global proc string[] listPolys(string $thisObject, string $thisShader) { string $listPolys[]; string $polysToPass[]; int $numOfShadersFound = 0; int $loopCounter = 0; print("\nThis is the Object we're working on " + $thisObject + "\n"); print("This is the Shader we Want " + $thisShader + "\n"); //check for dup shading groups string $transformNodes[] = `listRelatives -parent $thisObject`; //print($transformNodes); string $setList[] = `sets -q $thisShader`; //print($setList); //must tokenize our objects long name to use in following loops string $pathName[] = `listRelatives -f -p $thisObject`; if(startsWith($pathName[0], "|")){ $pathName[0] = `substring $pathName[0] 2 (size($pathName[0]))`; } print("\n this should be the path name "); print($pathName[0]); string $pathNamePieces[]; int $numNamePieces = `tokenize $pathName[0] "|" $pathNamePieces`; print("\n numNamePieces = " + $numNamePieces + "\n"); //shorten $thisObject name string $thisObjectNames[]; tokenize $thisObject "|" $thisObjectNames; $thisObject = $thisObjectNames[size($thisObjectNames) - 1]; print("\n this is the object we're working but shorter "); print($thisObject); print("\n"); //must loop through names for object starting w/ smallest. transform only for($setItem in $setList){ for($i = 0; $i < $numNamePieces; $i++){ string $checkName = ""; for($j = 0; $j < $i + 1; $j++){ if($j > 0){ $checkName = $pathNamePieces[($numNamePieces - $j) - 1] + "|" + $checkName; }else{ $checkName = $pathNamePieces[($numNamePieces - 1)]; } } //$checkName = $checkName + $thisObject; //print("\nDoes " + startString($setItem, size($checkName) + 3) + " equal " + ($checkName + ".f[") + "\n"); if(startString($setItem, size($checkName) + 3) == ($checkName + ".f[")){ //print("\n Found Match \n"); string $outPut[]; int $numTokens = `tokenize ($setItem) "." $outPut`; //$polysToPass[size($polysToPass)] = $checkName + "." + $outPut[(size($outPut) - 1)]; $polysToPass[size($polysToPass)] = $checkName + "." + $outPut[(size($outPut) - 1)]; } } } //must loop through names for object starting w/ smallest. with shape node if(size($polysToPass) < 1){ for($setItem in $setList){ for($i = 0; $i < $numNamePieces; $i++){ string $checkName = ""; for($j = 0; $j < $i + 1; $j++){ if($j > 0){ $checkName = $pathNamePieces[($numNamePieces - $j) - 1] + "|" + $checkName; }else{ $checkName = $pathNamePieces[($numNamePieces - 1)]; } } $checkName = $checkName + "|" + $thisObject; //print("\nDoes " + startString($setItem, size($checkName) + 3) + " equal " + ($checkName + ".f[") + "\n"); if(startString($setItem, size($checkName) + 3) == ($checkName + ".f[")){ //print("\n Found Match \n"); string $outPut[]; int $numTokens = `tokenize ($setItem) "." $outPut`; //$polysToPass[size($polysToPass)] = $checkName + "." + $outPut[(size($outPut) - 1)]; $polysToPass[size($polysToPass)] = $checkName + "." + $outPut[(size($outPut) - 1)]; } } } } /* for($setItem in $setList){ //print("\nDoes " + startString($setItem, size($transformNodes[0])+3) + " equal " + ($transformNodes[0] + ".f[") + "\n"); if(startString($setItem, size($transformNodes[0])+3) == ($transformNodes[0] + ".f[")){ //print("\n Found Match \n"); string $outPut[]; int $numTokens = `tokenize ($setItem) "." $outPut`; $polysToPass[size($polysToPass)] = $transformNodes[0] + "." + $outPut[(size($outPut) - 1)]; } } //if the above loop gets no matches try the shape node if(size($polysToPass) < 1){ string $shortOutPut[]; int $shortNumTokens = `tokenize ($thisObject) "|" $shortOutPut`; string $shortObjectName = $shortOutPut[$shortNumTokens - 1]; print("\n" + $shortObjectName + "\n"); for($setItem in $setList){ //print("\nDoes " + startString($setItem, size($shortObjectName)+3) + " equal " + ($shortObjectName + ".f[") + "\n"); if(startString($setItem, size($shortObjectName)+3) == ($shortObjectName + ".f[")){ //print("\n Found Match \n"); string $outPut[]; int $numTokens = `tokenize ($setItem) "." $outPut`; $polysToPass[size($polysToPass)] = $shortObjectName + "." + $outPut[(size($outPut) - 1)]; } } } //if the above loop gets no matches try the shape node with its transform node if(size($polysToPass) < 1){ //print("\npoop\n"); print($thisObject); string $shapeNodes[] = `listConnections -sh on $thisObject`; //print($shapeNodes); //print($thisObject + "|" + $shapeNodes[0]); for($setItem in $setList){ //print("\nDoes " + startString($setItem, (size($thisObject) + size($shapeNodes[0])+4)) + " equal " + ($thisObject + "|" + $shapeNodes[0] + ".f[") + "\n"); if(startString($setItem, (size($thisObject) + size($shapeNodes[0])+4)) == ($thisObject + "|" + $shapeNodes[0] + ".f[")){ print("\n Found Match \n"); string $outPut[]; int $numTokens = `tokenize ($setItem) "." $outPut`; $polysToPass[size($polysToPass)] = $thisObject + $shapeNodes[0] + "." + $outPut[(size($outPut) - 1)]; } } } */ print("\nlistPolys found " + size($polysToPass) + " entries in polyList\n"); return $polysToPass; } ////////////////////////////////////////////////////////////////////////////////////////////end listPolys global proc selectAllMultiSucks() { string $listMultiSucks[] = findMultiSucks(); select $listMultiSucks; for ($thisMultiSuck in $listMultiSucks) { select -add `listTransforms $thisMultiSuck`; } } ////////////////////////////////////////////////////////////////////////////////////////end selectAllMultiSucks global proc seperateAllByShader() { selectAllMultiSucks; seperateSelectedByShader; print "Seperate All By Shader Has Finished\n"; } /////////////////////////////////////////////////////////////////////////////////end seperateAllByShader global proc seperateSelectedByShader() { string $listMultiSucks[] = findSelectedMultiSucks(); //print $listMultiSucks; int $numMultiSucks = size($listMultiSucks); for ($whichMultiSuck = 0; $whichMultiSuck < $numMultiSucks; $whichMultiSuck++)//loop through all MultiSucks { int $thisLoopDidSomething = 0; string $thisObject = $listMultiSucks[$whichMultiSuck]; //print "$thisObject is "; //print $thisObject; //print "\n"; string $listShaders[] = listShaders($thisObject); $listShaders = stringArrayRemoveDuplicates($listShaders); //print "$listShaders is \n"; //print $listShaders; //print "\n"; int $numShaders = size($listShaders); print ($numShaders + "\n"); for ($whichShader = 0; $whichShader < $numShaders; $whichShader++) { string $thisShader = $listShaders[$whichShader]; string $listPolys[] = listPolys($thisObject, $thisShader); //print "$listPolys is \n"; //print $listPolys; //print "\n"; if(size($listPolys) < 1){ continue; } select -cl; for ($thisPoly in $listPolys) { //select -add ($thisObject + "." + $thisPoly); select -add ($thisPoly); } invertSelection; if (size(`ls -sl`) < 1) { continue; } $thisLoopDidSomething++;//if you get this far into the loop, it did something and you have to do clean up after select -cl; string $objParts[]; string $thisObjectShort; int $numObjParts = tokenize($thisObject, "|", $objParts); if ($numObjParts > 1) { $thisObjectShort = $objParts[($numObjParts - 1)]; } else { $thisObjectShort = $objParts[0]; } print("\n" + $thisObjectShort + "\n"); string $dupObject[] = `duplicate -n ($thisObjectShort + "_" + $thisShader) $thisObject`; print("\n this is the dup " + $dupObject[0] + "\n"); //must delete the duplicants children string $dupsChildren[] = `listRelatives -c -pa -type transform $dupObject[0]`; print("\nThese are the Dups Children "); print($dupsChildren); for($dupsChild in $dupsChildren){ delete $dupsChild; } string $dupShapes[] = `listRelatives -shapes $dupObject[0]`; if(size($dupShapes) > 0){ rename ($dupObject[0] + "|" + $dupShapes[0]) ($dupObject[0] + "_Shape"); $dupShapes = `listRelatives -shapes $dupObject[0]`; print(" this is the dup's shape " + $dupShapes[0] + "\n"); } //selectFacesByShader($dupObject[0], $thisShader); selectFacesByShader($dupShapes[0], $thisShader); invertSelection; delete; select $dupObject[0]; sets -e -forceElement $thisShader; } if($thisLoopDidSomething > 0){ string $thisObjectTrans[] = `listTransforms $thisObject`; //print "\n $thisObjectTrans is \n"; //print $thisObjectTrans; //print "\n\n"; string $thisObjectSibs[] = `ls -dag -lf $thisObjectTrans`; //print "\n $thisObjectSibs is \n"; //print $thisObjectSibs; //print "\n\n"; if (size($thisObjectSibs) == 1) { delete $thisObjectTrans[0]; }else{ delete $thisObject; } } } print "Seperate Selected By Shader Has Finished"; } //////////////////////////////////////////////////////////////////////////////end seperateSelectedByShader global proc listShadersOnSelection() { string $selectedTrans[] = `ls -l -sl`; int $numSelected = size($selectedTrans); string $selectedGeo[]; for ($whichTrans = 0; $whichTrans < $numSelected; $whichTrans++) { string $thisGeo[] = `listRelatives -pa -c -s $selectedTrans[$whichTrans]`; $selectedGeo = stringArrayCatenate($selectedGeo, $thisGeo); } global string $geosShaders[]; clear $geosShaders; for ($thatGeo in $selectedGeo) { //list shaders string $thisGeoShaders[] = listShaders($thatGeo); $geosShaders = stringArrayCatenate($geosShaders, $thisGeoShaders); } string $suckColumnLayout = "multiSuckerUI|menuBarLayoutAll|columnSuck"; if (`layout -exists multiSuckerUI|menuBarLayoutAll|columnSuck`) { multiSucker; } } ///////////////////////////////////////////////////////////////////////////////end listShadersOnSelection global proc selectFacesByShader(string $thatGeo, string $whichShader) { select -clear; string $polyList[] = listPolys($thatGeo, $whichShader); string $thatPoly; for ($thatPoly in $polyList) { //select -add ($thatGeo + "." + $thatPoly); select -add ($thatPoly); } //doMenuComponentSelection($thatGeo, "facet"); //updateComponentSelectionMasks; //updateObjectSelectionMasks; } ////////////////////////////////////////////////////////////////////////////////end selectFacesByShader global proc templateNonMultiSucks() { string $listMultiSucks[] = findMultiSucks(); int $numMultiSucks = size($listMultiSucks); string $listMultisTrans[]; //string $allTrans[] = `ls -l -tr`; //string $allTrans[] = `ls -l -dag -lf -tr`; string $allTrans[]; string $allGeo[] = `ls -l -g`; string $allLocatorShapes[] = `ls -l -g "locatorShape*"`; $allGeo = stringArrayRemove($allLocatorShapes, $allGeo); int $numGeo = size($allGeo); for ($whichGeo = 0; $whichGeo < $numGeo; $whichGeo++) { string $listGeoTrans[] = `listTransforms $allGeo[$whichGeo]`; string $thisGeoTransLong[] = `ls -l $listGeoTrans[0]`; $allTrans[$whichGeo] = $thisGeoTransLong[0]; } for ($whichMultiSuck = 0; $whichMultiSuck < $numMultiSucks; $whichMultiSuck++) { string $listThisTrans[] = `listTransforms $listMultiSucks[$whichMultiSuck]`; string $thisTransLong[] = `ls -l $listThisTrans[0]`; $listMultisTrans[$whichMultiSuck] = $thisTransLong[0]; } string $nonMultiSucks[] = stringArrayRemove($listMultisTrans, $allTrans); int $numNonSuck = size($nonMultiSucks); for ($whichNonSuck = 0; $whichNonSuck < $numNonSuck; $whichNonSuck++) { string $whatThePoop = $nonMultiSucks[$whichNonSuck]; string $templateValue = `setAttr ($whatThePoop + ".template") 1`; } print "Template Non-MultiSucks Has Finished"; } //////////////////////////////////////////////////////////////////////////////////end templateNonMultiSucks global proc unTemplateAll() { string $allTrans[] = `ls -l -tr`; string $allGeo[] = `ls -l -g`; string $thisTrans; for ($thisTrans in $allTrans) { string $templateValue = `setAttr ($thisTrans + ".template") 0`; } string $thisGeo; for ($thisGeo in $allGeo) { string $templateValue = `setAttr ($thisGeo + ".template") 0`; } } //////////////////////////////////////////////////////////////////////////////////////end unTemplateAll global proc multiSucker() { string $listMultiSucks[] = findMultiSucks(); int $numMultiSucks = size($listMultiSucks); global string $geosShaders[]; if (`window -exists multiSuckerUI`) deleteUI -window multiSuckerUI; { window -title "multiSucker" -width 300 -height 500 multiSuckerUI; menuBarLayout menuBarLayoutAll; menu -label "All multiSucks"; menuItem -label "Select All multiSucks" -command selectAllMultiSucks; menuItem -label "DO NOT USE THIS BUTTON, Seperate All By Shader" -command seperateAllByShader; menu -label "Selected multiSucks"; menuItem -label "Seperate Selected By Shader" -command seperateSelectedByShader; menuItem -label "Update Shaders on Selection" -command listShadersOnSelection; menu -label "Isolate"; menuItem -label "Template Non-MultiSucks" -command templateNonMultiSucks; menuItem -label "Untemplate All" -command unTemplateAll; columnLayout columnSuck; button -label "update" -command "listShadersOnSelection"; string $noDupShaderList[] = stringArrayRemoveDuplicates($geosShaders); int $numShaders = size($noDupShaderList); if ( $numShaders > 0 ) { string $selectedGeo[] = `ls -l -sl`; string $thisGeo[] = `listRelatives -pa -c -s $selectedGeo[0]`; string $thatGeo = $thisGeo[0]; //print ($thatGeo + "\n"); for ($whichShader = 0; $whichShader < $numShaders; $whichShader++) { string $shaderName[] = `listConnections ($noDupShaderList[$whichShader] + ".surfaceShader")`; button -label ($shaderName[0]) -command ( "selectFacesByShader(\"" + $thatGeo + "\", \"" + $noDupShaderList[$whichShader] + "\")" ); } } clear $geosShaders; showWindow multiSuckerUI; //scriptJob //-parent multiSuckerUI //-runOnce true //-event "SelectionChanged" "listShadersOnSelection"; } } multiSucker;