/************************************************************************************* This script finds meshes in a MB file that have textures assigned to them but the textures no longer exist in the location where Maya is looking for them. A list of the missing textures is written out to a TMP file in the same location where the MB is saved if there are no missing textures no file is written but a message pops up to inform user that no textures are missing. This only tests for lambert, phong, phong2 and blinn type shaders, specific other types could be added... To Use: Just make sure that the file your checking has been saved because the script needs to be able to find the current location of the file to write a text file to. Beside that just run the script if there are no meshes with missing texture a message will say so, if there are meshes with missing textures the script will write out a text file that says what Materials have missing textures and where Maya expects the textures to be -get array of all the textures in the file -get node type of all the textures -get array of all the shapes in the file -find all shapes with Sets associated with them -list connection for all Sets -list all connection for type lambert, phong... -compare the array of connections for type lambert with the array of all the textures in the file -make a new array made up of all common elements of both arrays (trying to narrow down to just File types) -get texture name for all the elements in the array -test to see if that file exist -if the file doesn't exist save it to an array and print that array to a file written by jonathan paton and completed on 2/26/08 *************************************************************************************/ global proc writeMissingTexture() { string $allTextures[] = `ls -textures`; //all testures in file string $allShapes[] = `ls -shapes`; //allShapes in file //call to get a list of all the shadergroups used by the shapes string $shapeSetArray[] = `getShapeConnection($allShapes)`; //loop that looks at each member in $shapeSetArray and detetemines which elements are //of type shader string $listArrayShape[]; string $shaderList[]; int $arrayCounter = 0; for ($element in $shapeSetArray) { $listArrayShape = `listConnections $element`; string $shaderName = `findShaderType($listArrayShape)`; $shaderList[$arrayCounter] = $shaderName; $arrayCounter++; } string $commonFiles[] = getCommonElements($allTextures, $shaderList); string $commonFilesReDux[] = stringArrayRemoveDuplicates($commonFiles); //need to get the paths for all the memembers of $commonFilesReDux string $misLocated[] = validPaths($commonFilesReDux); if (`size $misLocated` > 0) { string $pathAndNameArray[] = getFilePath(); string $printMe = stringArrayToString($misLocated, "\n"); $fileName = ( $pathAndNameArray[0] + "/" + $pathAndNameArray[1] + "_missingTextures" + ".tmp" ); $fileId=`fopen $fileName "w"`; fprint $fileId $printMe; fclose $fileId; confirmDialog -title "File written to" -message ( $pathAndNameArray[0] + "/" + $pathAndNameArray[1] + "_missingTextures" + ".tmp" ) -button "Ok" -defaultButton "Yes"; } else { confirmDialog -title "Confirm" -message "No missing textures" -button "Ok" -defaultButton "Yes"; } } //proc takes a node of type "file" and returns what shader (material) is connected to it proc string whatShaderAmI(string $fileName) { string $listArray[] = `listConnections $fileName`; for ($element in $listArray) { if (((`nodeType $element`) == "lambert") || ((`nodeType $element`) == "blinn") || ((`nodeType $element`) == "phong") || ((`nodeType $element`) == "phongE")) { return $element; } } } //proc that gets the path of all the members of $commonFilesReDux and test to see if those //files actually exist where Maya thinks they do proc string[] validPaths(string $commonFilesReDux[]) { string $singleFile; int $arrayCounter = 0; string $misLocated[]; for ($element in $commonFilesReDux) { $singleFile = `getAttr ($element + ".fileTextureName")`; if ((`file -q -exists $singleFile`) == 0) { $misLocated[$arrayCounter] = whatShaderAmI($element);; $arrayCounter++; $misLocated[$arrayCounter] = $singleFile; $arrayCounter++; } } return $misLocated; } //proc gets an array of shaders and finds out which one is of type "file1" that //point to a texture. then compares that array to an array of all nodes of type "file1" //to deteremine which of the connections to the shaders are valid. it will return a list of //valid nodes that point to textures proc string[] getCommonElements(string $allTextures[], string $shaderList[]) { string $needed[]; string $refinedShaderList[]; int $arrayCounter = 0; int $arrayCounter2 = 0; //this next bit get the connections for every element in the shaderList array //and compares it to every element in allTexture array. for ($element in $shaderList) { $refinedShaderList = `listConnections $element`; $arrayCounter2++; for ($element1 in $refinedShaderList) { for ($element2 in $allTextures) { if ($element1 == $element2) { $needed[$arrayCounter] = $element1; $arrayCounter++; } } } } return $needed; } //this proc finds out what element in an array is of a type that can point to a texture (i.e. //lambert, phong, blinn...) then returns the name of the shader to the main proc proc string findShaderType(string $listArray[]) { string $listNode; //gets the nodeType of each element //runs through array and comparas each element to a list of shader types (lambert, blinn..) //then when it finds an element of a shader type it returns it for ($element in $listArray) { $listNode = `nodeType $element`; if (($listNode == "lambert") || ($listNode == "blinn") || ($listNode == "lambert") || ($listNode == "phong") || ($listNode == "phongE")) { return $element; } } } //this proc gets an array of all the nodes of type "Shape" in the file and finds the ones that are //connected to a "Set" then it returns an array of them because they should be a shader group proc string[] getShapeConnection(string $findShapeConnections[]) { string $foundShapeConnection[]; string $allShapeConnection[]; int $arrayCounter = 0; for ($element in $findShapeConnections) { $allShapeConnection = `listSets -object $element`; if (`size $allShapeConnection` > 0) { $foundShapeConnection[$arrayCounter] = $allShapeConnection[0]; $arrayCounter++; } } return $foundShapeConnection; } proc string[] getFilePath() { //path where Maya scene is located string $filePath = `file -q -sceneName`; if ($filePath == "") { error "save your file"; } //change string to string array w/o "/" string $filePathArray[] = stringToStringArray($filePath, "/"); //get size of array int $pathArraySize = size($filePathArray); //get the name of the Maya file string $currentFileName = $filePathArray[($pathArraySize - 1)]; //array used to hold elements that will become path w/o file name string $pathBackToString[]; //for testing clear $pathBackToString; //test number for loop int $count = 0; //feeds original array back to temp array but leaves off last elemant do{ $pathBackToString[$count] = $filePathArray[$count]; $count++; } while ($count < ($pathArraySize - 1)); //turns path array back to string string $filePathString = stringArrayToString($pathBackToString, "/"); //remove the extention from the Maya file name string $filePathNameArray[] = stringToStringArray($currentFileName, "."); string $pathAndNameArray[]; $pathAndNameArray[0] = $filePathString; $pathAndNameArray[1] = $filePathNameArray[0]; return $pathAndNameArray; } /********************END******************************/