VRay File Gamma

This script allows the user to add the VRay gamma correct tag to the selected file nodes and set your gamma value.

To Run: Select the file nodes you want to change the run the script.

#VRay File Gamma Attributes for Maya version 1.0.0
#Bryanna London
#!/usr/bin/env python
import maya.cmds as cmds
import maya.mel as mel

#delete window if a window already exisits
if cmds.window('gammaWindow', exists=True):
    cmds.deleteUI('gammaWindow')

#Create my GUI
def createGUI():
    #window layout
    gammaWindow= cmds.window('gammaWindow',title="Gamma Correction", rtf=True)
    cmds.columnLayout(adjustableColumn= True)
    cmds.floatFieldGrp('textureInputGamma',numberOfFields=1, label="Texture Input Gamma", precision= 2, value1=2.2)
    cmds.rowColumnLayout(numberOfRows = 1)
    cmds.button( label='GAMMA ON', width= 100, command=('fileSelection()'))
    cmds.button( label='GAMMA OFF', width= 100, command=('gammaOff()'))
    cmds.setParent('..')
    cmds.columnLayout()
    cmds.button( label='Close', width= 200, command=('cmds.deleteUI(\"' + gammaWindow + '\", window=True)'))
    cmds.setParent('..')
    cmds.showWindow('gammaWindow')

#Query Values inputed in GUI for Subdivision tab
def queryValues():

   x= cmds.floatFieldGrp('textureInputGamma', query=True, value=True)

   #query floatFieldGrp
   queriedValuesX = x
   #print and return values from GUI
   print queriedValuesX
   return queriedValuesX[0]

#File Selection Definition
def fileSelection():

    #Queried Values
    queriedValuesX = queryValues()
    print queriedValuesX

    #Define variable textures as all the selected file nodes
    tex = ''
    textures = cmds.ls(selection = True, visible=True, type = 'file')

    #if there are file nodes selected run the for loop
    if cmds.ls(sl=True, type = 'file'):

        #for all the selected files, add the gamma attribute
        for tex in textures:

            mel.eval('vray addAttributesFromGroup %s vray_file_gamma 1' % tex)
            cmds.evalDeferred("cmds.setAttr('%s.vrayFileGammaEnable', %s)" %(tex, 1))
            cmds.evalDeferred("cmds.setAttr('%s.vrayFileColorSpace', %s)" %(tex, 1))
            cmds.evalDeferred("cmds.setAttr('%s.vrayFileGammaValue', %s)" %(tex, queriedValuesX))

    #if nothing is selected don't do anything
    else:

        cmds.confirmDialog(title='Confirm', message='Nothing Selected. Nothing Done.' , button =['Ok'])

#Off button command to turn the Gamma tags off
#this will run if the Turn SubD Off button is selected
def gammaOff():

    files = cmds.ls(selection = True, dag = True, lf = True, visible=True, type = 'file')

    if cmds.ls(sl=True):

        for fi in files:

            mel.eval('vray addAttributesFromGroup %s vray_file_gamma 0' % fi)

    else:

        cmds.confirmDialog(title='Confirm', message='Nothing Selected. Nothing Done.' , button =['Ok'])

#show window
createGUI()

© 2016 Bryanna London

Advertisements