renderManager.py

WIP script for maya written in python. Pops up a window with buttons for creating various renderlayers

############################################################
## 
## Rendermanager v1.0 
## ------------------
## Python script for making various renderpasses
## 
## 
## creator:	Jan-Erik "Jonne" Östman
## mail: 	jonne@jonne.net
## web: 	www.jonne.net
## 
############################################################


import maya.cmds as cmds


'''
Todo-list:
----------
- add textfields for custom naming of the layer
- add buttons for adding and removing objects to layer
- add button for switching to the layer
- add button for deleting the layer
- add button for renaming the layer

'''

## Get selected objects
sel = cmds.ls(sl=1)

## Check if the window exists
if cmds.window(renderWindow, exists=True):
	cmds.deleteUI(renderWindow, window=True)


## Define window
renderWindow = cmds.window	(
				title="Rendermanager", 
				wh=(250,60)				
				)

## Layout
cmds.columnLayout( adjustableColumn=True )

## Buttons

#spec
cmds.textField('txtSpec', tx='Specular')
cmds.checkBox('chkBoxSpec', label='Include all lights', value=1 )
cmds.button( label='Make specular', command='makeSpecular()' )

#diffuse
cmds.textField('txtDiffuse', tx='Diffuse')
cmds.checkBox('chkBoxDiffuse', label='Include all lights', value=1 )
cmds.button( label='Make diffuse', command='makeDiffuse()' )



## Init the window
cmds.showWindow( renderWindow )


##
## Make Specular pass
## - creates a layer override and turns off emit diffuse on selected objects
## - creates a layer override and turns off raytracing
##
def makeSpecular():

	## Get custom name and errorcheck
	layerName = cmds.textField('txtSpec', q=1, tx=True)
	
	if layerName == '':
		layerName = 'Specular'

	## List all lights
	lightSelection = cmds.ls( lights=True)

	## Check checkbox value
	if ( cmds.checkBox('chkBoxSpec', q=1, value=True) ) == 1:
		cmds.select(lightSelection, add=1)
		

	## Create new renderlayer with selected objects
	cmds.createRenderLayer(name=layerName, nr=1, mc=1)

	
	## Turn off diffuse
	for c,cur in enumerate(lightSelection):
		cmds.editRenderLayerAdjustment( lightSelection[c] + '.emitDiffuse' )
		cmds.setAttr( lightSelection[c]+ '.emitDiffuse', 0)


	## Turn off raytracing
	cmds.editRenderLayerAdjustment('miDefaultOptions.rayTracing')
	cmds.setAttr ('miDefaultOptions.rayTracing', 0)

	## Clear selection
	cmds.select(clear=True)

##
## Make Diffuse pass
## - creates a layer override and turns off emit specular on selected objects
## - creates a layer override and turns off raytracing
##
def makeDiffuse():

	## Get custom name and errorcheck
	layerName = cmds.textField('txtDiffuse', q=1, tx=True)

	if layerName == '':
		layerName = 'Diffuse'

	## List all lights
	lightSelection = cmds.ls( lights=True)

	## Check checkbox value
	if ( cmds.checkBox('chkBoxDiffuse', q=1, value=True) ) == 1:
		cmds.select(lightSelection, add=1)

	## Create new renderlayer with selected objects
	cmds.createRenderLayer(name=layerName, nr=1, mc=1)


	## Turn off specular
	for c,cur in enumerate(lightSelection):
		cmds.editRenderLayerAdjustment( lightSelection[c] + '.emitSpecular' )
		cmds.setAttr( lightSelection[c]+ '.emitSpecular', 0)


	## Turn off raytracing
	cmds.editRenderLayerAdjustment('miDefaultOptions.rayTracing')
	cmds.setAttr ('miDefaultOptions.rayTracing', 0)

	## Clear selection
	cmds.select(clear=True)

I wish to do something Great and Wonderful, but I must start by doing the little things like they were Great and Wonderful”
~ Albert Einstein