Wednesday, September 5, 2012


     I had the idea to write a python script that exported all your file contents neatly into a text file. I wrote some of it, but the important parts were written by old chocolate milk Dan Bradham. Just replace the directory with where you want the text file to be written.

import maya.cmds as cmds
import os

def sceneFileContents(filePath):
    Creates a text file that lists all your nodes in order of node types.
    It puts it in your shot maya directory as a text file.
    fileName = cmds.file(query = True, sn = True) 
    nodes = = True)
    size = len(nodes)/2
    sceneContents = ["%s:\n\nThere are %i objects in this scene.\n" % (fileName,size)]

    #Build a Dictionary
    node_dictionary = {}
    for i in range(0, len(nodes), 2):
        node = nodes[i]
        nodeType = nodes[i+1]
        if not nodeType in node_dictionary:
            #If nodeType is not in dictionary, assign node as a list item
            node_dictionary[nodeType] = [node]
            #If nodeType is in dictionary, append node to the existing list

    for k in node_dictionary:
        sceneContents.append ('\nNode Type : %s (%s Nodes)\n' %(k,len(node_dictionary[k])))
        for i, each in enumerate(node_dictionary[k]):
            sceneContents.append  ('    %d:%s\n' % (i, each))

    sceneTxt = open(r'%ssceneContent.txt'%filePath, 'w')    

if __name__ == '__main__':


Post a Comment