[Maya Python] Checking texture file paths.

[Nuke] Despill expressions.
January 14, 2015
Show all

[Maya Python] Checking texture file paths.

This small piece of code was written on the fly while I was debugging a large lighting scene. The assets in the scene was created by different offices and needed to be synced together for the shot. When the renders didn’t look right, the first thing that needed to be checked was whether we have all the texture we need.

How ever, with hundreds of assets and almost thousands of textures in the scene, there were simply no way to check all the files in Maya manually to find what textures are missing. This script does a quick check for the following:

1. prints out all the files in the scene and their absolute path.

2. prints out all the folders the files are in.

3. check if the folders exists.

4. check if those folders are empty.

 

import maya.cmds as mc
import os

def texStatus():
    #quick check stats for all the texture files in the scene.

    texDirs = []
    fileList = mc.ls(type = "file")
    
    #prints out all files and their absolute path.
    print "\n========= All File Path ==============="
    print "Found", str(len(fileList)), "files in the scene:\n"
    
    for f in fileList:
        fPath = mc.getAttr(f+".fileTextureName")
        
        dirPath = os.path.split(fPath)[0]
        
        print f + ":"
        print fPath + "\n"

        if dirPath not in texDirs:
            texDirs.append(dirPath)

    #prints out all folders being used for the textures
    print "\n========= All FOLDERS USED ==============="
    for p in texDirs:
        print p

    #prints out the folder is doesnt's exist
    print "\n========= File Path not Exist ==============="
    for p in texDirs:
        try:
            if not os.path.exists(p):
                print p
        except e:
            print error

    #prints out the folder if it's empty
    print "\n========= File Path Empty ==============="
    
    for p in texDirs:
        try:
            if len(os.listdir(p)) == 0:
                print p
        except e:
            print error

#run
texStatus()

Leave a Reply

Your email address will not be published. Required fields are marked *