############################################################################# # felix.mel Version 0.1 by Andrew Osiow Copyright 2008 # # with thanks to Jeremy Birn for his original scripting sugestions # # This is small but handy lighting utility that has two main features: # First, it builds a custom attribute spreadsheet for all selected lights # any scalable attribute can be added to the spreadsheet including attributes that are not available through the channel box # or the standard attribute spreadsheet. # Second, It renders the contribution of each light in the scene into a separate image. # Each image is stored in the renderview and is annotated with the name of matching lights name. # # This is a conversion from felix.mel # I've lowered the version number because it doesn't have all the functions # It does make a customizable spreadsheet for lights but it does not render # each light's contribution to a separate image yet # to be added soon # ############################################################################# import maya.cmds as cmds import maya.mel as mel #need to add eval command that processes import command at main - script editor name space def addAttr2List(): # adds an attribute to the Light list Table # grab attributes from first light currentLight = cmds.ls(lt=True, hd=True) attributeList = cmds.listAttr(currentLight[0], s=True) #attributeList = attributeList.sort() # delete saved Window Pref if cmds.windowPref('addFelixWindow', exists=True): cmds.windowPref('addFelixWindow', remove=True) # create a window structure if cmds.window('addFelixWindow', exists=True): cmds.deleteUI('addFelixWindow', window=True) addFelixWin = cmds.window( 'addFelixWindow', title="Add Attribute", widthHeight=(20, 10), rtf=1, s=0) addFelixLayout = cmds.formLayout(numberOfDivisions=100) # create gui to list light attributes addFelixList = cmds.textScrollList('addFelixList', w=180, numberOfRows=8, allowMultiSelection=False) # add attribute list for currentAttribute in attributeList: cmds.textScrollList('addFelixList', edit=True, a=currentAttribute) # Standard Gui Buttons addAttrListButton = cmds.button('addAttrListButton', width=90 ,height=26, label="Add", align="center", command="grabNewAttr()") closeAttrListButton = cmds.button('closeAttrListButton', width=90 ,height=26, label="Close", align="center", command="cmds.deleteUI('addFelixWindow', window=True)") cmds.formLayout (addFelixLayout, edit=True, attachForm=[(addFelixList, 'top', 4), (addFelixList, 'left', 4), (addFelixList, 'right', 4), (addAttrListButton, 'left', 4), (addAttrListButton, 'bottom', 4), (closeAttrListButton, 'bottom', 4), (closeAttrListButton, 'right', 4)], attachControl=[(addAttrListButton, 'top', 12, addFelixList), (closeAttrListButton, 'top', 12, addFelixList)]) cmds.showWindow(addFelixWin) # end addAttr2List definition def grabNewAttr(): # grabs attr from list newAttribute = cmds.textScrollList('addFelixList', q=True, si=True) currentAttrList = cmds.spreadSheetEditor('lightTableObj', q=True, fal=True) currentAttrList += newAttribute cmds.spreadSheetEditor('lightTableObj', e=True, fal= currentAttrList) cmds.deleteUI('addFelixWindow', window=True) # end grabNewAttr definition def removeSelectAttr(): # removes any selected attr from the list currentAttrList = cmds.spreadSheetEditor('lightTableObj', q=True, fal=True) selectedAttrList = cmds.spreadSheetEditor('lightTableObj',q=True, sla=True) for attr in selectedAttrList: # coverting string from UI form to interCaps attr = attr.replace(' ','') firstLetter = attr[0] firstLetter = firstLetter.lower() restOfString = attr[1:] newAttr = firstLetter + restOfString currentAttrList.remove(newAttr) cmds.spreadSheetEditor('lightTableObj', e=True, fal=currentAttrList) # end removeSelectAttr definition #def renderEachLight(): # # renders each Light contribution to the scene separately # lightList = cmds.ls(lt=True) # # disable all light from default group # for ($currentLight in $lightList) # { //get transform Node # string $lightTransform[] = `listRelatives -p $currentLight`; # //find connection # string $setConnection[] = `connectionInfo -dfs ($lightTransform[0]+".instObjGroups")`; # if ($setConnection[0]!="") // if connected then disconnect # disconnectAttr ($lightTransform[0]+".instObjGroups[0]") $setConnection[0]; # } # // reenable each light for a render # for ($currentLight in $lightList) # {//get transform Node # string $lightTransform[] = `listRelatives -p $currentLight`; # // enable light # connectAttr -nextAvailable ($lightTransform[0]+".instObjGroups") defaultLightSet.dagSetMembers; # // add lightname text # renderWindowRender redoPreviousRender renderView; # // store the image # renderWindowEditor -e -pca (" "+$lightTransform[0]) renderView; # // render an image # renderWindowMenuCommand keepImageInRenderView renderView; # // disable the light again # string $setConnection[] = `connectionInfo -dfs ($lightTransform[0]+".instObjGroups")`; # if ($setConnection[0]!="") // if connected then disconnect # disconnectAttr ($lightTransform[0]+".instObjGroups[0]") $setConnection[0]; # } # // enable all lights again # for ($currentLight in $lightList) # {//get transform Node # string $lightTransform[] = `listRelatives -p $currentLight`; # // enable light # connectAttr -nextAvailable ($lightTransform[0]+".instObjGroups") defaultLightSet.dagSetMembers; # } #} def felix(): # delete saved Window Pref if cmds.windowPref('felixWindow', exists=True): cmds.windowPref('felixWindow', remove=True) # create a window structure if cmds.window('felixWindow', exists=True): cmds.deleteUI('felixWindow', window=True) felixWin = cmds.window( 'felixWindow', title="Felix Lighter v0.2", iconName='FL', widthHeight=(20, 10), rtf=1, s=0 ) felixLayout = cmds.formLayout(numberOfDivisions=100) # create Felix Gui # add Spread Sheet Editor lightBorder = cmds.frameLayout('lightBorderObj', label="Light List", cll=0, bs="in") lightPane = cmds.paneLayout('lightPaneObj', cn="vertical2", w=274, h=80) activeList = cmds.selectionConnection(activeList=True) lightTable = cmds.spreadSheetEditor('lightTableObj', mainListConnection=activeList) # add one starter/default attribute to light spreadsheet cmds.spreadSheetEditor('lightTableObj', edit=True, fal=["intensity"], showShapes=True, keyableOnly=False) # can not create render view window - need to investigate # open standard render window # felixRender = cmds.renderWindowEditor # set parent back to Felix main layout cmds.setParent(felixLayout) # make add and delete Attribute Buttons addAttrButton = cmds.button('addAttrButton', width=120, height=26, label="Add Attr", align="center", command="addAttr2List()") removeSelectAttr = cmds.button('removeSelectAttr', width=120, height=26, label="Remove Attr", align="center", command="removeSelectAttr()") # Standard Gui Buttons renderButton = cmds.button('renderButton', width=90 ,height=26, label="Render", align="center", command="renderEachLight()") closeButton = cmds.button('closeButton', width=90 ,height=26, label="Close", align="center", command="cmds.deleteUI('felixWindow', window=True)") # layout buttons cmds.formLayout (felixLayout, edit=True, attachForm=[(lightBorder, 'top', 4), (lightBorder, 'left', 4), (addAttrButton, 'left', 20), (removeSelectAttr, 'right', 20), (renderButton, 'bottom', 4), (renderButton, 'left', 4), (closeButton, 'bottom', 4), (closeButton, 'right', 4)], attachControl=[(addAttrButton, 'top', 12, lightBorder), (removeSelectAttr, 'top', 12, lightBorder), (renderButton, 'top', 12, addAttrButton), (closeButton, 'top', 12, addAttrButton)]) # open render view if one isn't already open if not cmds.window('renderViewWindow', exists=True): mel.eval('RenderViewWindow') cmds.showWindow(felixWin) # end felix definition