I often have to move large Maya scenes around from one system or network to a completely different one, and it inevitably causes paths to break. (Using Maya projects isn’t an option in these cases for various reasons). When your scene has hundreds of textures, that’s a huge annoyance! Maya tries to report in the Script Editor, but it repeats a lot and also re-reports when you scroll in the Hypershade. Grrr, arrgh. So, first thing’s first: we need to get a solid list of missing textures and where they are currently pulling their texture files from.
The most helpful command here is ‘filetest’. True to its name, it tests raw system files for access and type information. The -s flag specifically checks that the file exists AND is greater than zero in size.
global proc checkExistence($allFiles) { string $allFiles[] = `ls -typ file`; string $eachFile; string $missingFiles[]; int $numMissingFiles = 0; int $count; for($eachFile in $allFiles) { $failure = 0; string $textureAttr = $eachFile + ".fileTextureName"; //print ("File Texture Name: " + $textureAttr + "\n"); string $texturePath = `getAttr $textureAttr`; //print("File Texture Path: " + $texturePath + "\n"); if(`filetest -s $texturePath`) { print("File exists!\n"); } else { print("File does NOT exist!\n"); //print("File Texture Path: " + $texturePath + "\n"); $numMissingFiles++; $count = $numMissingFiles - 1; $missingFiles[$count] = $texturePath; print("Files in Array: " + $missingFiles[$count] + "\n"); } } print("Number of Missing Files: " + $numMissingFiles + "\n"); if($numMissingFiles > 0) { print("Number of Missing Files: " + $numMissingFiles + "\n"); //we're gonna do some fun stuff here in a later post! } }
But of course it would really be more helpful if we could write out our results to file instead of a block of text in the Script Editor. (I mean, you could just copy/paste said block into a text file, but if the good Lord had intended us to do that, he wouldn’t have invented scripting now would he?) So! I’ll probably address file I/O sometime soon.