Add VRay gamma attributes to all 8 bit file nodes


/ Published in: Python
Save to your folder(s)

A function that adds gamma attribs to the image files that are 8 bit in nature (aka not EXR or HDR) so that you can get to a linear workflow easily


Copy this code and paste it in your HTML
  1. def vrayAddGamma():
  2. import maya.cmds as cmds
  3. import maya.mel as mel
  4. import time, os
  5. allFileNodes = cmds.ls(type='file') # look for file nodes
  6. nonFloatFiles = []
  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. #print fileName
  13. fileExt = os.path.splitext(fileName)[1].lower()[1:] # get the extention
  14. #fileExt = fileExt.lower()[1:]
  15. #print fileExt
  16. if fileExt != 'exr' or fileExt != '.hdr': # test for hdr and exr
  17. nonFloatFiles.append(curFile)
  18. mel.eval('vray addAttributesFromGroup ' + curFile + ' vray_file_gamma 1') # add the proper vray stuff to the attribs
  19. time.sleep(5) # have to sleep because maya is a pain in the asssssssssss!!!
  20. allFileNodes = cmds.ls(type='file') # look for file nodes
  21. for curFile in nonFloatFiles:
  22. if cmds.objExists(curFile + '.vrayFileGammaEnable'):
  23. cmds.setAttr (curFile + '.vrayFileGammaEnable', 1) # make sure the gamma correction is enabled
  24. cmds.setAttr (curFile + '.vrayFileColorSpace', 2) # set it to sRGB
  25. else :
  26. print 'The attribute for VRay is not found in %s' % curFile
  27.  
  28. vrayAddGamma()

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.