//JustListSwitch // // Date: 2004/04/16 // Author: Dai Sato dstruevision@dstruevision.com http://www.dstruevision.com // Procedure Name: JustListSwitch // // Description: This scripts list up all shading switch connected to a material. // You can add and remove and tweak inputs of those shading switch. // When you use "Get Files And Connect", you have to name files with obeying to the naming rule of // Deep Paint 3D like this: materialName.shapeName.Color(Bump,Glow,Shine,Opacity).tga // For example, file name can be "blinn1.right_hand_1.Color.tga". // ---Left-Right file sharing--- //If you've connected "blinn1.right_hand_1.Color.tga" file node to right_hand_1 in switch list and" //added left_hand_1 to the list, you can automatically connect "blinn1.right_hand_1.Color.tga" //file node to left_hand_1, too." To use this function, you have to use "_"(underbar) after "right or left. //Recommended workflow is that use "Remove all connections from switch" then "add surface" then "Get Files and Connect". proc string extractFileName(string $path) { string $tokens[]; int $numTokens = `tokenize $path "/" $tokens`; return $tokens[$numTokens-1]; } proc string extractExtension(string $extractedFilename) { string $tokens[]; int $numTokens = `tokenize $extractedFilename "." $tokens`; return $tokens[$numTokens -1]; } proc string cutExtension(string $fileName) { string $tokens[]; string $noExtension =""; string $buffer = ""; int $numTokens = `tokenize $fileName "." $tokens`; for ($i=$numTokens-2;$i>=0;$i--) { $noExtension = ($tokens[$i] + "." + $buffer); $buffer = $noExtension; } return $noExtension; } proc string returnDir(string $path) { string $tempFilePath = ""; string $buffer = ""; string $tokens[]; int $numTokens = `tokenize $path "/" $tokens`; for ($i=$numTokens-2;$i>=0;$i--) { $tempFilePath = ($tokens[$i] + "/" + $buffer); $buffer = $tempFilePath; } return $tempFilePath; } global proc whenMaterialSelected () { string $selection[] = `textScrollList -q -si materiallList`; select -cl; select -add $selection[0]; } proc string myCutPrefix(string $switch) { string $tokens[]; int $numTokens = `tokenize $switch "__" $tokens`; return $tokens[$numTokens-1]; } global proc whenSwitchSelected () { string $selection[] = `textScrollList -q -si mySwitchList`; string $exactName = myCutPrefix($selection[0]); select -cl; select -add $exactName; } global proc myAddMats (){ textScrollList -edit -ra materiallList; string $sceneMaterials[] = `ls -mat`; int $materialNumber = size($sceneMaterials); int $counter = 0; while ($counter<$materialNumber) { textScrollList -edit -append $sceneMaterials[$counter] materiallList; $counter +=1 ; } } global proc myAddShapes (){ textScrollList -edit -ra connectedShapesList; string $currentSelection[] = `ls -sl`; if($currentSelection[0] != "") { string $checkNode = `nodeType $currentSelection[0]`; if($checkNode == "tripleShadingSwitch"||$checkNode == "singleShadingSwitch") { string $conList[] = `listConnections -s true -c true ($currentSelection[0]+".input")`; if(!($conList[0]=="")) { string $pickedNumber = myPickNumberString($conList[(size($conList))-2]); int $intNumber = $pickedNumber; if(size($conList)>=2) { for($i=0;$i<=$intNumber;$i++) { string $connectedShape[] = `listConnections -s true ($currentSelection[0]+".input["+$i+"]"+".inShape")`; if(!($connectedShape[0]=="")) { textScrollList -edit -append $connectedShape[0] connectedShapesList; } } } } } } } proc string myReturnCommandString(string $selectedTab, string $found, string $currentSelection) { string $myCommandString = ""; string $tmp = "Current Selection is "+$currentSelection; if($found=="found") { switch($selectedTab) { case "Materials": break; case "Switch": $myCommandString = `text -edit -label $tmp selectedMaterial`; break; case "Input": break; default: break; } } else{ switch($selectedTab) { case "Materials": break; case "Switch": $myCommandString = `text -edit -label "No Material is selected" selectedMaterial`; break; case "Input": break; default: break; } } return $myCommandString; } proc string checkType(string $check){ string $nodeType = `nodeType $check`; string $class []= `getClassification $nodeType`; if($class[0]=="shader/surface") { return "true"; } else { return "false"; } } global proc mySelectedMaterial(string $selectedTab) { string $currentSelection[] = `ls -sl`; if($currentSelection[0] != "") { $checkFlag = checkType($currentSelection[0]); if($checkFlag == "true") { string $matName = $currentSelection[0]; myReturnCommandString($selectedTab, "found", $currentSelection[0]); } else { myReturnCommandString($selectedTab, "NotFound", $currentSelection[0]); } } else { myReturnCommandString($selectedTab, "NotFound", $currentSelection[0]); } } global proc mySelectedSwitch(string $selectedTab) { string $currentSelection[] = `ls -sl`; if($currentSelection[0] != "") { string $checkNode = `nodeType $currentSelection[0]`; if($checkNode == "tripleShadingSwitch"||$checkNode == "singleShadingSwitch") { string $tmp = "Current Selection is "+$currentSelection[0]; text -edit -label $tmp selectedSwitch; } else { text -edit -label "No Switch is Selected!" selectedSwitch; } } else { text -edit -label "No Switch is Selected!" selectedSwitch; } } global proc JustListSwitchTabChanged() { string $selectedTab = `tabLayout -q -st listSwitchTab` ; mySelectedMaterial($selectedTab); mySelectedSwitch($selectedTab); if($selectedTab=="JLS_Materials"){ myAddMats(); window -e -width 180 -height 445 JustListSwitchWindow; } if($selectedTab=="JLS_Switch"){ myCollectSwitch(); window -e -width 250 -height 445 JustListSwitchWindow; } if($selectedTab=="JLS_Shapes"){ myAddShapes(); window -e -width 320 -height 500 JustListSwitchWindow; } } global proc editMenuText(int $selectedItem) { switch($selectedItem) { case 1: text -e -label "Current Filter Type is Off" textFilterType; break; case 2: text -e -label "Current Filter Type is Mipmap" textFilterType; break; case 3: text -e -label "Current Filter Type is Box" textFilterType; break; case 4: text -e -label "Current Filter Type is Quadratic" textFilterType; break; case 5: text -e -label "Current Filter Type is Quartic" textFilterType; break; case 6: text -e -label "Current Filter Type is Gaussian" textFilterType; break; default: break; } } global proc mySelectDir(string $folder,string $something) { textField -e -tx $folder searchFilesField; } global proc myGetDir() { fileBrowserDialog -m 4 -fc "mySelectDir" -ft "omage" -an "Select Dir"; } proc string myExtractAttribute(string $attributeName) { string $tokens[]; int $numTokens = `tokenize $attributeName "." $tokens`; return $tokens[$numTokens-1]; } proc string myConnectionList(string $switch){ string $newString; if(!($switch=="")) { string $tmpCon[] = `listConnections -d true -p true $switch`; for($i=0;$i=2) { for($i=0;$i<=$intNumber;$i++) { string $switchFlag; if($checkNode == "singleShadingSwitch") { $switchFlag=".inSingle"; } if($checkNode == "tripleShadingSwitch") { $switchFlag=".inTriple"; } string $checkShapePlug[] = `listConnections -s true -d false -c false -p true ($currentSelection[0]+".input["+$i+"]"+".inShape")`; string $checkShapeCon[] = `listConnections -s true -d false -c true -p false ($currentSelection[0]+".input["+$i+"]"+".inShape")`; string $checkTriplePlug[]= `listConnections -s true -d false -c false -p true ($currentSelection[0]+".input["+$i+"]"+$switchFlag)`; string $checkTripleCon[]= `listConnections -s true -d false -c true -p false ($currentSelection[0]+".input["+$i+"]"+$switchFlag)`; if(!($checkShapeCon[0]=="")) { disconnectAttr $checkShapePlug[0] $checkShapeCon[0]; } if(!($checkTripleCon[0]=="")) { disconnectAttr $checkTriplePlug[0] $checkTripleCon[0]; } } } } } } } proc string myfindFileMatch(string $conList, string $foundFile, string $switch) { string $tmpAttrType = myConnectionList($switch); string $tokens1[]; int $numTokens1 = `tokenize $tmpAttrType "__" $tokens1`; string $exactAttrType = myCutKakko($tokens1[$numTokens1-2]); string $typeMatchFlag = "false"; string $destMat = myGetDestMat($switch); string $tokens[]; int $numTokens = `tokenize $foundFile "." $tokens`; if($numTokens>=4) { string $fileType = $tokens[$numTokens-2]; string $materialName = $tokens[$numTokens-4]; switch($fileType){ case "Color": if($exactAttrType=="color"&&$destMat==$materialName) { $typeMatchFlag = "true"; } break; case "Opacity": if($exactAttrType=="transparency"&&$destMat==$materialName) { $typeMatchFlag = "true"; } break; case "Glow": if($exactAttrType=="incandescence"&&$destMat==$materialName) { $typeMatchFlag = "true"; } break; case "Bump": if($exactAttrType=="bumpValue"&&$destMat==$materialName) { $typeMatchFlag = "true"; } break; case "Shine": if($exactAttrType=="specularColor"&&$destMat==$materialName) { $typeMatchFlag = "true"; } break; default: break; } if($typeMatchFlag=="true") { return $tokens[$numTokens-3]; } } return ""; } proc string myExtractLeftRightPrefix(string $fileName, string $change) { string $tokens[]; string $tokens2[]; string $baseShapeName = ""; int $numTokens = `tokenize $fileName "." $tokens`; int $numTokens2 = `tokenize $tokens[1] "_" $tokens2`; for($i=1;$i<$numTokens2;$i++) { string $tmp = "_"+$tokens2[$i]; $baseShapeName = $baseShapeName + $tmp; } if($change=="LeftRight") { return $tokens2[0]; } if($change=="baseShapeName") { return $baseShapeName; } } proc myfindLeftRight(int $intNumber, string $newFile, string $currentSelection, string $foundFiles, string $switchType) { string $flag = myExtractLeftRightPrefix($foundFiles, "LeftRight"); string $baseShapeName = myExtractLeftRightPrefix($foundFiles, "baseShapeName"); string $searchShapeName; if($flag=="left") { $searchShapeName = "right"+$baseShapeName; } if($flag=="right") { $searchShapeName = "left"+$baseShapeName; } string $justTest = $intNumber; print $justTest; for($i=0;$i<=$intNumber;$i++) { string $checkShape[] = `listConnections -s true -d false ($currentSelection+".input["+$i+"]"+".inShape")`; print ($searchShapeName+"\n"); print ($checkShape[0]+"\n"); print ("----------------"+"\n"); if($checkShape[0]==$searchShapeName&&$switchType=="Single") { connectAttr -f ($newFile + ".outAlpha") ($currentSelection+".input["+$i+"].inSingle"); } if($checkShape[0]==$searchShapeName&&$switchType=="Triple") { connectAttr -f ($newFile + ".outColor") ($currentSelection+".input["+$i+"].inTriple"); } } } proc myAttachFileNode(int $i, int $intNumber, string $currentSelection, string $foundFiles, string $checkType, int $conNumber, string $leftRightEnable){ $newFile = `shadingNode -asTexture file`; $newPlace2d = `shadingNode -asUtility place2dTexture`; setAttr ($newFile+".fileTextureName") -type "string" $foundFiles.fileTextureName; connectAttr ($newPlace2d + ".coverage") ($newFile + ".coverage"); connectAttr ($newPlace2d + ".translateFrame") ($newFile + ".translateFrame"); connectAttr ($newPlace2d + ".rotateFrame") ($newFile + ".rotateFrame"); connectAttr ($newPlace2d + ".mirrorU") ($newFile + ".mirrorU"); connectAttr ($newPlace2d + ".mirrorV") ($newFile + ".mirrorV"); connectAttr ($newPlace2d + ".stagger") ($newFile + ".stagger"); connectAttr ($newPlace2d + ".wrapU") ($newFile + ".wrapU"); connectAttr ($newPlace2d + ".wrapV") ($newFile + ".wrapV"); connectAttr ($newPlace2d + ".repeatUV") ($newFile + ".repeatUV"); connectAttr ($newPlace2d + ".offset") ($newFile + ".offset"); connectAttr ($newPlace2d + ".rotateUV") ($newFile + ".rotateUV"); connectAttr ($newPlace2d + ".outUV") ($newFile + ".uv"); connectAttr ($newPlace2d + ".outUvFilterSize") ($newFile + ".uvFilterSize"); if($checkType=="singleShadingSwitch") { connectAttr -f ($newFile + ".outAlpha") ($currentSelection+".input["+$conNumber+"].inSingle"); if($leftRightEnable=="1") { myfindLeftRight($intNumber, $newFile, $currentSelection, $foundFiles, "Single"); } } if($checkType=="tripleShadingSwitch") { connectAttr -f ($newFile + ".outColor") ($currentSelection+".input["+$conNumber+"].inTriple"); if($leftRightEnable=="1") { myfindLeftRight($intNumber, $newFile, $currentSelection, $foundFiles, "Triple"); } } } global proc myGetFilesAndConnect(){ string $currentSelection[] = `ls -sl`; string $tmp = `textField -q -tx searchFilesField`; string $foundFiles[] = `getFileList -folder $tmp`; string $type =""; string $leftRightEnable = `checkBoxGrp -q -v1 checkLeftRighSharing`; if(!($currentSelection[0]=="")) { string $checkType = `nodeType $currentSelection[0]`; if($checkType=="tripleShadingSwitch"||$checkType=="singleShadingSwitch"){ string $conList[] = `listConnections -s true -c true ($currentSelection[0]+".input")`; if(!($conList[0]=="")) { string $pickedNumber = myPickNumberString($conList[(size($conList))-2]); int $intNumber = $pickedNumber; print ($pickedNumber+"\n"); int $progressMax = size($conList); progressBar -edit -beginProgress -isInterruptable true -status "Calculation ..." -maxValue $progressMax connectFileProgressBar; if(size($conList)>=2) { for($i=0;$i