Custom Extra Tex

This script is if you want to create a extra tex render element but only want to apply it to specific objects. This will create a extra tex, let you apply a texture to it, and set it up so it only applies the extra tex to the selected objects.

To Run: Just select the objects you want to apply the extra tex to and run the script. If you want to create a quick multi matte choose Matte. If you want to apply a file texture choose Custom File. If you want to apply a Maya texture choose Other Texture and it will set everything up and you just have to attach the texture.

#Custom Extra Tex version 1.0.0
#For Maya. Tested in version 2014 with VRay 2.4
#Bryanna London www.bryannalondon.com
#!/usr/bin/env python

#This script is if you want to create a extra tex render element but
#only want to apply it to specific objects. This will create a extra tex,
#let you apply a texture to it, and set it up so it only applies the extra
#tex to selected objects.
############################
#TO USE:
# 1. Select objects you want to apply the extra tex to
# 2. Run Script
# 3. Name your Extra Tex
# 4. Choose a type. Matte is for a Matte, Custom File lets you choose a file to apply
# Other is if you want to apply a maya texture it sets up the extra tex so you just have to link the maya texture node
############################
import maya.cmds as cmds
import maya.mel as mel

#####Features to add####
#Removing objects from set
#Use exsisting set

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

def createGUI():
    #window layout
    customExtraTexWindow = cmds.window('customExtraTexWindow',title="Custom Extra Tex", rtf=True)
    cmds.columnLayout(adjustableColumn= True, rowSpacing= 3)
    cmds.rowColumnLayout(numberOfRows = 1)
    cmds.text( label='Extra Tex Name')
    cmds.textField('extraTexName', width = 224)
    cmds.setParent('..')
    cmds.rowColumnLayout(numberOfRows = 1)
    cmds.button( label='Matte', width= 112, command=('rampMatte()'))
    cmds.button( label='Custom File', width= 112, command=('fileExtraTex()'))
    cmds.button( label='Other Texture', width= 112, command=('extraTex()'))
    cmds.setParent('..')
    cmds.columnLayout()
    cmds.button( label='Close', width= 336, command=('cmds.deleteUI(\"' + customExtraTexWindow + '\", window=True)'))
    cmds.setParent('..')
    cmds.setParent('..')
    cmds.showWindow('customExtraTexWindow')

#Queried Values
def queryExTex():

    nameValue = cmds.textField('extraTexName', query = True, text = True)
    return nameValue

def extraTex():

    queriedValueName = queryExTex()

    if len(queriedValueName) > 0:
        #Put selected objects in Set
        extraTexSet = cmds.sets(name= queriedValueName + '_set')

        #Create Extra Tex Render Element
        extraRE = mel.eval('vrayAddRenderElement ExtraTexElement')
        #Rename Extra Tex
        eTexName = cmds.rename(extraRE, queriedValueName)
        #Set Explicit Channel name to Text Field Name
        cmds.setAttr(eTexName + '.vray_explicit_name_extratex', queriedValueName, type = 'string')
        #Connect Set to Exclude list
        cmds.connectAttr(extraTexSet + '.usedBy', queriedValueName + '.vray_exclude_list_extratex')
        cmds.setAttr(queriedValueName + '.vray_exclude_list_as_inclusive_extratex', 1)
    else:

        cmds.confirmDialog(title='Confirm', message='Need to Add Extra Tex Name' , button =['Ok'])

#For Mattes
#Make Ramp and Connect to Extra Tex
def rampMatte():

    #run extra tex creation def
    extraTex()
    #Run Queried Value
    queriedValueName = queryExTex()

    if len(queriedValueName) > 0:
        ramp = cmds.shadingNode('ramp', name = 'mask_ramp', asTexture = True)
        #Make Ramp only red
        cmds.setAttr(ramp + '.colorEntryList[0].color', 1, 0, 0, type = 'double3')
        place2dTextureNode = cmds.shadingNode('place2dTexture', asUtility = True)
        cmds.connectAttr(place2dTextureNode + '.outUV', ramp + '.uvCoord')
        cmds.connectAttr(place2dTextureNode + '.outUvFilterSize', ramp + '.uvFilterSize')

        #Connect to Mask Extra Tex
        cmds.connectAttr(ramp + '.outColor', queriedValueName + '.vray_texture_extratex')

    else:

        cmds.confirmDialog(title='Confirm', message='Need to Add Extra Tex Name' , button =['Ok'])

#For Files
#Make File Node and Connect to Extra Tex
def fileExtraTex():

    #Choose File and Attach
    rootDirectory = cmds.workspace(query = True, rootDirectory = True) + 'sourceimages/'
    imageFilters = "Image Files(*.png *.jpg *.exr *.hdr *.tif);; All Files (*.*)"
    selectFile = cmds.fileDialog2(startingDirectory = rootDirectory, fileMode = 1, fileFilter = imageFilters)

    if selectFile != None:

        #run extra tex creation def
        extraTex()
        #Run Queried Value
        queriedValueName = queryExTex()

        if len(queriedValueName) > 0:

            fileTex = cmds.shadingNode('file', name = 'fileExTex', asTexture = True)
            cmds.setAttr(fileTex + '.filterType', 0)
            place2dTextureNode = cmds.shadingNode('place2dTexture', asUtility = True)

            cmds.connectAttr(place2dTextureNode + '.coverage', fileTex + '.coverage')
            cmds.connectAttr(place2dTextureNode + '.translateFrame', fileTex + '.translateFrame')
            cmds.connectAttr(place2dTextureNode + '.rotateFrame', fileTex + '.rotateFrame')
            cmds.connectAttr(place2dTextureNode + '.mirrorU', fileTex + '.mirrorU')
            cmds.connectAttr(place2dTextureNode + '.mirrorV', fileTex + '.mirrorV')
            cmds.connectAttr(place2dTextureNode + '.stagger', fileTex + '.stagger')
            cmds.connectAttr(place2dTextureNode + '.wrapU', fileTex + '.wrapU')
            cmds.connectAttr(place2dTextureNode + '.wrapV', fileTex + '.wrapV')
            cmds.connectAttr(place2dTextureNode + '.repeatUV', fileTex + '.repeatUV')
            cmds.connectAttr(place2dTextureNode + '.offset', fileTex + '.offset')
            cmds.connectAttr(place2dTextureNode + '.rotateUV', fileTex + '.rotateUV')
            cmds.connectAttr(place2dTextureNode + '.noiseUV', fileTex + '.noiseUV')
            cmds.connectAttr(place2dTextureNode + '.vertexUvOne', fileTex + '.vertexUvOne')
            cmds.connectAttr(place2dTextureNode + '.vertexUvTwo', fileTex + '.vertexUvTwo')
            cmds.connectAttr(place2dTextureNode + '.vertexUvThree', fileTex + '.vertexUvThree')
            cmds.connectAttr(place2dTextureNode + '.vertexCameraOne', fileTex + '.vertexCameraOne')
            cmds.connectAttr(place2dTextureNode + '.outUV', fileTex + '.uvCoord')
            cmds.connectAttr(place2dTextureNode + '.outUvFilterSize', fileTex + '.uvFilterSize')

            cmds.setAttr('%s.fileTextureName' %(fileTex), selectFile[0], type = 'string')
            #Connect to Mask Extra Tex
            cmds.connectAttr(fileTex + '.outColor', queriedValueName + '.vray_texture_extratex')

        else:

            cmds.confirmDialog(title='Confirm', message='Need to Add Extra Tex Name' , button =['Ok'])
    else:

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

createGUI()

© 2016 Bryanna London