Advertisement
throb

Create mentalray .map files from all existing non map files

Apr 11th, 2012
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.34 KB | None | 0 0
  1. def createMapFiles():
  2.     import maya.cmds as cmds   
  3.     import maya.mel as mel
  4.     import time, os, subprocess
  5.     allFileNodes = cmds.ls(type='file') # look for file nodes
  6.     nonMapFiles = []
  7.     for curFile in allFileNodes:
  8.        
  9.         cmds.setAttr (curFile + '.filterType', 0) # turn off the damned filtering
  10.         fileName = cmds.getAttr(curFile + '.fileTextureName') # get the filename
  11.         if fileName != '': # test for stupid user
  12.             fileExt = os.path.splitext(fileName)[1].lower()[1:] # get the extention
  13.             if fileExt != 'map' : # test for anything but map files
  14.                 nonMapFiles.append(curFile)
  15.     for curFile in nonMapFiles:
  16.         curFileName = cmds.getAttr(curFile + '.fileTextureName') # get the filename
  17.         newFileName = curFileName.replace(os.path.splitext(fileName)[1].lower()[1:],'map')
  18.         bin_path = 'C:/Program Files/Autodesk/Maya2012/bin' # change this to the correct installation path of maya
  19.         cmd = '%s/imf_copy -r -p %s %s' % (bin_path,curFileName, newFileName) # create the output command
  20.         subprocess.call (cmd) # run the command
  21.         if os.path.exists (newFileName) : #make sure the map file exists
  22.             cmds.setAttr(curFile + '.fileTextureName' , newFileName, type='string') # set the attr to replace the file with the map
  23.         else:
  24.             print 'Error with map conversion for %s - %s' % (curFile, curFileName) # was it messed up?  tell the user
  25.  
  26. createMapFiles()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement