Rect Light

This script creates a VRay Rect Light, allows you to rename it, connect a texture if you would like, and it sets the light defaults to what I normally start out with.

To Run: Just run the script.

#Create Rect Light Maya Version 1.0.0
#Bryanna London
#!/usr/bin/env python

import maya.cmds as cmds
import maya.mel as mel

#rect light def
def createRectLight():

    #Name Creation Prompt
    namePrompt = cmds.promptDialog(title = 'Name Light', message = 'Enter Light Name', button=['OK', 'Cancel'],
                 defaultButton = 'OK', cancelButton = 'Cancel', dismissString = 'Cancel')

    if namePrompt == 'OK':
        name = cmds.promptDialog(query = True, text = True)

    else:
        name = 'VRayLightRect'

    #create vray rect light
    rectLight = cmds.shadingNode( 'VRayLightRectShape' , asLight=True )

    #rename light
    rectLightName = cmds.rename( rectLight , name )

    #Set default attributes
    cmds.setAttr('%s.invisible' %(rectLightName), 1)
    cmds.setAttr('%s.intensityMult' %(rectLightName), 10)
    cmds.setAttr('%s.uSize' %(rectLightName), 3)
    cmds.setAttr('%s.vSize' %(rectLightName), 3)

    #Rect Tex Prompt
    texturePrompt = cmds.confirmDialog(title = 'File Texture', message = 'Would you like to plug a file texture into ' + rectLightName + '?',
                                       button = ['Yes', 'No'], defaultButton = 'Yes', cancelButton = 'No', dismissString = 'No')
    #If Texture Prompt is Yes
    if texturePrompt == 'Yes':
        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 a file was selected: set up file
        if selectFile:

            #create file node and 2d texture node
            fileTex = cmds.shadingNode('file', name = rectLightName + '_file', asTexture = True)
            place2dTextureNode = cmds.shadingNode('place2dTexture', asUtility = True)

            #connect the selected image to the file node. Set filter type.
            cmds.setAttr('%s.fileTextureName' %(fileTex), selectFile[0], type = 'string')
            cmds.setAttr('%s.filterType' %(fileTex), 0)

            #connect place2dTexture to file
            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')

            #Turn on rect tex
            cmds.setAttr('%s.useRectTex' %(rectLightName), 1)

            #Get Light Shape Node
            rectLightShape = cmds.listRelatives( rectLightName, shapes = True)

            #connect file to light
            cmds.connectAttr(fileTex + '.outColor', rectLightShape[0] + '.rectTex')

    cmds.select(rectLightName)

createRectLight()

© 2016 Bryanna London

Advertisements