Dome Light

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

To Run: Just run the script.

#Create Dome 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 createDomeLight():

    #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 = 'VRayLightDome'

    #create vray rect light
    domeLight = cmds.shadingNode( 'VRayLightDomeShape' , asLight=True )

    #rename light
    domeLightName = cmds.rename( domeLight , name )

    #Set default attributes
    cmds.setAttr('%s.invisible' %(domeLightName), 1)
    cmds.setAttr('%s.domeSpherical' %(domeLightName), 1)
    cmds.setAttr('%s.locatorScale' %(domeLightName), 3)

    #Rect Tex Prompt
    texturePrompt = cmds.confirmDialog(title = 'File Texture', message = 'Would you like to plug a file texture into ' + domeLightName + '?',
                                       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 environment texture
            fileTex = cmds.shadingNode('file', name = domeLightName + '_file', asTexture = True)
            vrayPlaceEnvTex = cmds.shadingNode('VRayPlaceEnvTex', name = 'vrayPlaceEnvTex', 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)

            #set environment texture to sphereical
            cmds.setAttr('%s.mappingType' %(vrayPlaceEnvTex), 2)

            # connect VRayPlaceEnvTex node
            cmds.connectAttr(vrayPlaceEnvTex + '.outUV', fileTex + '.uvCoord')
            cmds.connectAttr(domeLightName + '.worldMatrix[0]', vrayPlaceEnvTex + '.transform')

            #Turn on rect tex
            cmds.setAttr('%s.useDomeTex' %(domeLightName), 1)

            #Get Light Shape Node
            domeLightShape = cmds.listRelatives( domeLightName, shapes = True)

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

    cmds.select(domeLightName)

createDomeLight()

© 2016 Bryanna London

Advertisement