def remove_layer_override(): current_render_layer = mc.editRenderLayerGlobals(currentRenderLayer=1, q=1) if current_render_layer != 'defaultRenderLayer': aov_names = mc.ls(type='aiAOV') if aov_names: for aov_name in aov_names: mc.editRenderLayerAdjustment('%s.enabled' % aov_name, remove=1)
def _create_aov(self): """ Create a new aov callback :return: """ aov_name = self.le_idName.text() if not ("aiAOV_%s" % aov_name) in cmds.ls(type="aiAOV"): utils.create_new_aov(aov_name) # Enable AOV on current layer as override render_layer = cmds.editRenderLayerGlobals(query=True, crl=True) cmds.editRenderLayerAdjustment("aiAOV_%s.enabled" % aov_name, layer=render_layer) cmds.setAttr("aiAOV_%s.enabled" % aov_name, 1) utils.create_connect_aov_shader(aov_name) self._refresh_content() return
def vrayEditREButton ( buttonPush ): selectedSceneRE = vraySelectedSceneRE() selectedActiveRE = vraySelectedActiveRE() if (buttonPush == 'enable'): if (selectedSceneRE != None): for x in selectedSceneRE: attr = (x + '.enabled') cmds.editRenderLayerAdjustment(attr) cmds.setAttr(attr, 1); vrayUpdateUI() else: cmds.warning('No Render Elements are selected. Please Select a Render Elements in Scene.') if (buttonPush == 'disable'): if (selectedActiveRE != None): for x in selectedActiveRE: attr = (x + '.enabled') cmds.editRenderLayerAdjustment(attr) cmds.setAttr(attr, 0); vrayUpdateUI() else: cmds.warning('No Render Elements are selected. Please Select a Render in Render Layer.') if (buttonPush == 'delete'): if (selectedSceneRE != None): for x in selectedSceneRE: cmds.delete(x) vrayUpdateUI() else: cmds.warning('No Render Elements are selected. Please Select a Render Elements in Scene.')
def closeAllAOVs(*args): all_aovs = cmds.ls('aiAOV_*') for i in all_aovs: try: cmds.editRenderLayerAdjustment('%s.enabled' % i) cmds.setAttr('%s.enabled' % i, 0) except: cmds.setAttr('%s.enabled' % i, 0)
def dpaf_frameRangeMenuItemCmd(self, attrName, textName, layer, remove, *args): if remove: cmds.editRenderLayerAdjustment(attrName, lyr= layer, r= 1) self.dpaf_tintOverrideColor(textName, 0) else: cmds.editRenderLayerAdjustment(attrName, lyr= layer) self.dpaf_tintOverrideColor(textName, 1)
def switchLayerAOV(trigger): existsAOVs = aovs.AOVInterface().getAOVNodes(names=True) for existsAOV in existsAOVs: #aovName = existsAOV[0] aovNode = existsAOV[1].getName() cmds.editRenderLayerAdjustment(aovNode + ".enabled") cmds.setAttr(aovNode + ".enabled", trigger)
def disableImagePlane(): objs = mc.ls(typ='imagePlane') for obj in objs: if not mc.editRenderLayerGlobals(q=1, crl=1) == 'defaultRenderLayer': mc.editRenderLayerAdjustment(obj + ".displayMode") mc.setAttr(obj + ".displayMode", 0) if not mc.editRenderLayerGlobals(q=1, crl=1) == 'defaultRenderLayer': mc.editRenderLayerAdjustment(obj + ".type") mc.setAttr(obj + ".type", 1)
def disableImagePlane(): objs = mc.ls(typ="imagePlane") for obj in objs: if not mc.editRenderLayerGlobals(q=1, crl=1) == "defaultRenderLayer": mc.editRenderLayerAdjustment(obj + ".displayMode") mc.setAttr(obj + ".displayMode", 0) if not mc.editRenderLayerGlobals(q=1, crl=1) == "defaultRenderLayer": mc.editRenderLayerAdjustment(obj + ".type") mc.setAttr(obj + ".type", 1)
def set_override(old, new, attr, renderlayer): from maya import cmds from reveries.maya import lib if not lib.is_using_renderSetup(): cmds.editRenderLayerAdjustment(new + "." + attr, layer=renderlayer) # (TODO) Set value to overrided renderlayer is not # implemented. return
def set_attribute_id(object_name, id_set, id_color): """ :param object_name: the name of a maya node as a string :param id_set: the name of an aov as a string :param id_color: tje name of an aov's rgb color as a string :return: """ shape_node = cmds.listRelatives(object_name, allDescendents=True, fullPath=True, shapes=True)[0] id_color = id_color.split("_Neg")[0] channel_values = ["Red_", "Green_", "Blue_"] channels = ["", "_Alpha"] for ch in channels: myAttr = "mtoa_constant_%s%s" % (id_set, ch) # Add ID Attribute if not exist if not cmds.attributeQuery(myAttr, node=shape_node, exists=True): cmds.addAttr(shape_node, ln=myAttr, nn=id_set + ch, uac=1, at="float3") for c in channel_values: cmds.addAttr(shape_node, ln=c + id_set + ch, at="float", p=myAttr) # Create a layer Override for all attributes cmds.editRenderLayerAdjustment("%s.%s" % (shape_node, myAttr)) # Set all values to 0: cmds.setAttr("%s.%s" % (shape_node, myAttr), 0, 0, 0, type="double3") if id_color == "Holdout": continue # Set Id Color as per user input if id_color in ch and id_color == "Alpha": cmds.setAttr("%s.%s" % (shape_node, myAttr), 1, 1, 1, type="double3") if id_color not in ch and ch != "_Alpha": cmds.setAttr("%s.%s" % (shape_node, myAttr), int(id_color in channel_values[0]), id_color in channel_values[1], id_color in channel_values[2]) return
def checkStatusSet(self,layer=None,value=None,attr=None): cmds.editRenderLayerAdjustment(attr,layer=layer) connection_list = cmds.listConnections(attr, plugs=True) if connection_list is not None: for connection in connection_list: attr_component_list = connection.split(".") if attr_component_list[0] == layer: attr = ".".join(attr_component_list[0:-1]) cmds.setAttr("%s.value" % attr, value)
def connectArnold(): nodes = getRegionNode() if len(nodes) > 1: for node in nodes: renderlayer = cmds.listConnections(node + '.renderlayer')[0] if renderlayer != 'defaultRenderLayer': cmds.editRenderLayerAdjustment( 'defaultArnoldRenderOptions.regionMinX', 'defaultArnoldRenderOptions.regionMaxX', 'defaultArnoldRenderOptions.regionMinY', 'defaultArnoldRenderOptions.regionMaxY', layer=renderlayer) for node in nodes: #create container container = cmds.container(n=node + '_arnoldConnection') cmds.addAttr(container, ln='minX', defaultValue=1) #create utility nodes minpms = cmds.shadingNode('plusMinusAverage', asUtility=True) maxpms = cmds.shadingNode('plusMinusAverage', asUtility=True) cmds.container(container, e=True, addNode=[minpms, maxpms]) #setup nodes cmds.setAttr(minpms + '.operation', 2) cmds.connectAttr(node + '.renderheight', minpms + '.input1D[0]') cmds.connectAttr(node + '.maxY', minpms + '.input1D[1]') cmds.setAttr(maxpms + '.operation', 2) cmds.connectAttr(node + '.renderheight', maxpms + '.input1D[0]') cmds.connectAttr(node + '.minY', maxpms + '.input1D[1]') cmds.connectAttr(node + '.minX', container + '.minX') #connect to arnold renderlayer = cmds.listConnections(node + '.renderlayer')[0] cmds.editRenderLayerGlobals(currentRenderLayer=renderlayer) cmds.refresh() cmds.connectAttr(container + '.minX', 'defaultArnoldRenderOptions.regionMinX') cmds.connectAttr(minpms + '.output1D', 'defaultArnoldRenderOptions.regionMinY') [clp, pms] = clampMax(node + '.maxX', node + '.renderwidth', 'defaultArnoldRenderOptions.regionMaxX') cmds.container(container, e=True, addNode=[clp, pms]) [clp, pms] = clampMax(maxpms + '.output1D', node + '.renderheight', 'defaultArnoldRenderOptions.regionMaxY') cmds.container(container, e=True, addNode=[clp, pms])
def set_layer_attr(node_type, attr_name, attr_value, layer): # Set currendt layer cmds.editRenderLayerGlobals(currentRenderLayer=layer) nodes = cmds.ls(type=node_type) for node in nodes: cmds.editRenderLayerAdjustment(node + '.' + attr_name, layer=layer) cmds.setAttr(node + '.' + attr_name, attr_value)
def overrided(self, value): """set an override for attribute :param value: set overrded attribute or not :type value: bool""" lay = mc.editRenderLayerGlobals(query=True, currentRenderLayer=True) if not 'defaultRenderLayer' == lay: if value: mc.editRenderLayerAdjustment(self.fullname, layer=lay) else: mc.editRenderLayerAdjustment(self.fullname, remove=True)
def set_aov_enabled_adjust(status): current_render_layer = mc.editRenderLayerGlobals(currentRenderLayer=1, q=1) if current_render_layer == 'defaultRenderLayer': set_aov_enabled(status) else: aov_names = mc.ls(type='aiAOV') if aov_names: for aov_name in aov_names: mc.editRenderLayerAdjustment("%s.enabled" % aov_name) mc.setAttr('%s.enabled' % aov_name, status)
def overrided(self, value): """set an override for attribute :param value: set overrded attribute or not :type value: bool""" lay = mc.editRenderLayerGlobals( query=True, currentRenderLayer=True ) if not 'defaultRenderLayer' == lay: if value: mc.editRenderLayerAdjustment( self.fullname ,layer= lay ) else: mc.editRenderLayerAdjustment( self.fullname , remove=True )
def changeRS(): # switch to mental ray rendering cmds.setAttr('defaultRenderGlobals.ren', 'mentalRay', type='string') # create the mental ray rendering nodes so they can be changed mel.eval('miCreateDefaultNodes') # set filter to gaussian as layer overide cmds.editRenderLayerAdjustment( 'miDefaultOptions.filter', layer='ao' ) cmds.setAttr('miDefaultOptions.filter', 2); # set the max/min samples cmds.setAttr('miDefaultOptions.maxSamples', 2) cmds.setAttr('miDefaultOptions.minSamples', 0)
def change_rs(): """changes mental ray render settings to appropriate defaults""" # switch to mental ray rendering cmds.setAttr("defaultRenderGlobals.ren", "mentalRay", type="string") # create the mental ray rendering nodes so they can be changed mel.eval("miCreateDefaultNodes") # set filter to gaussian as layer overide cmds.editRenderLayerAdjustment("miDefaultOptions.filter", layer="ao") cmds.setAttr("miDefaultOptions.filter", 2) # set the max/min samples cmds.setAttr("miDefaultOptions.maxSamples", 2) cmds.setAttr("miDefaultOptions.minSamples", 0)
def lightAovOverrides(*args): nodes = returnLightNode() aovSet = set() for node in nodes: aovSet.add(cmds.getAttr('%s.aiAov' % node)) activeAOVs = returnActiveAOVs() for aov_ in aovSet: for aovType in activeAOVs: aovNode = 'aiAOV_%s_%s' % (aov_, aovType) if cmds.objExists(aovNode): cmds.editRenderLayerAdjustment('%s.enabled' % aovNode) cmds.setAttr('%s.enabled' % aovNode, 1)
def doIt(self, argList): st = cmds.ls(sl=1) cmds.createRenderLayer(st) cmds.vray("objectProperties", "add_single") cmds.editRenderLayerGlobals(currentRenderLayer="renderLayer") cmds.setAttr("vrayobjectproperties.primaryVisibility", 0) cmds.editRenderLayerAdjustment( "vrayobjectproperties.primaryVisibility") cmds.setAttr("vrayobjectproperties.primaryVisibility", 1) cmds.rename("renderLayer", str(st)) cmds.rename("vrayobjectproperties", str(st))
def connectArnold(): nodes=getRegionNode() if len(nodes)>1: for node in nodes: renderlayer=cmds.listConnections(node+'.renderlayer')[0] if renderlayer!='defaultRenderLayer': cmds.editRenderLayerAdjustment( 'defaultArnoldRenderOptions.regionMinX', 'defaultArnoldRenderOptions.regionMaxX', 'defaultArnoldRenderOptions.regionMinY', 'defaultArnoldRenderOptions.regionMaxY', layer=renderlayer ) for node in nodes: #create container container=cmds.container(n=node+'_arnoldConnection') cmds.addAttr(container,ln='minX',defaultValue=1) #create utility nodes minpms=cmds.shadingNode('plusMinusAverage',asUtility=True) maxpms=cmds.shadingNode('plusMinusAverage',asUtility=True) cmds.container(container,e=True,addNode=[minpms,maxpms]) #setup nodes cmds.setAttr(minpms+'.operation',2) cmds.connectAttr(node+'.renderheight',minpms+'.input1D[0]') cmds.connectAttr(node+'.maxY',minpms+'.input1D[1]') cmds.setAttr(maxpms+'.operation',2) cmds.connectAttr(node+'.renderheight',maxpms+'.input1D[0]') cmds.connectAttr(node+'.minY',maxpms+'.input1D[1]') cmds.connectAttr(node+'.minX',container+'.minX') #connect to arnold renderlayer=cmds.listConnections(node+'.renderlayer')[0] cmds.editRenderLayerGlobals( currentRenderLayer=renderlayer) cmds.refresh() cmds.connectAttr(container+'.minX','defaultArnoldRenderOptions.regionMinX') cmds.connectAttr(minpms+'.output1D','defaultArnoldRenderOptions.regionMinY') [clp,pms]=clampMax(node+'.maxX',node+'.renderwidth','defaultArnoldRenderOptions.regionMaxX') cmds.container(container,e=True,addNode=[clp,pms]) [clp,pms]=clampMax(maxpms+'.output1D',node+'.renderheight','defaultArnoldRenderOptions.regionMaxY') cmds.container(container,e=True,addNode=[clp,pms])
def toggleRenderElements(attributeList): for attr in attributeList: renderElement = 'm_' + attr if cmds.objExists(renderElement): cmds.editRenderLayerAdjustment('%s.enabled' % renderElement) cmds.setAttr('%s.enabled' % renderElement, 1) else: print( "toggleRenderElements: vrayRenderElement: %s does not exist." % renderElement) return 0
def killOverrides(self,*args): """ remove all render layer overrides in the asset. """ # for each render layer, list all adjustments, then attempt to remove each one. deadOvers = [] for rlayer in cmds.ls(type='renderLayer'): adjs = cmds.editRenderLayerAdjustment(rlayer, q=1, lyr=1) if adjs != None: for adj in cmds.editRenderLayerAdjustment(rlayer, q=1, lyr=1): try: deadOvers.append(adj) cmds.editRenderLayerAdjustment(adj,r=1,lyr=rlayer) except: deadOvers.append(adj+' (FAILED)') return deadOvers
def dpaf_adjRenderCamera(self, value, *args): layer = cmds.optionMenu('af_layerMenu', q= 1, v= 1) if layer == 'No Renderable Layer' or layer.startswith('-'): layer = 'masterLayer' layer = 'defaultRenderLayer' if layer == 'masterLayer' else layer override = 0 if '_dim' in cmds.iconTextButton('af_overriBtn', q= 1, image= 1) else 1 # geather selected camera camerAdjList = cmds.textScrollList('af_cameraScr', q= 1, si= 1) if camerAdjList: for cam in camerAdjList: cmaShapeAttr = cmds.listRelatives(cam, s= 1)[0] + '.renderable' if override and layer != 'defaultRenderLayer': cmds.editRenderLayerAdjustment(cmaShapeAttr, lyr= layer) self.dpaf_setOverrideData(cmaShapeAttr, layer, value) self.dpaf_getCameraList()
def enable_element(self, layer, args): # List all render elements elements = cmds.ls(type="VRayRenderElement") for element in elements: for tag, enabled in args.items(): if cmds.attributeQuery('tag', node=element, exists=True): if cmds.getAttr(element + ".tag") == tag: print layer, tag, enabled, element # Create render layer adjustments # You still need to be on the layer in order to make an ajusment cmds.editRenderLayerGlobals(currentRenderLayer=layer) cmds.editRenderLayerAdjustment(element + ".enabled", layer=layer) cmds.setAttr(element + ".enabled", enabled)
def proxSet(self, mode, value): over = cmds.checkBoxGrp(self.myCheck2, q=1, v1=1) user_attr = ['.idm', '.mm', '.visibilityMode'] tmp = cmds.ls(sl=1, dag=1, type='mesh') if tmp == []: #cmds.confirmDialog(m='未选择物体', button='确定') cmds.warning('未选择物体') return rsProxys = cmds.listConnections(tmp, type='RedshiftProxyMesh') for i in rsProxys: if over == 1: if 'defaultRenderLayer' != cmds.editRenderLayerGlobals( q=1, currentRenderLayer=1): cmds.editRenderLayerAdjustment(i + user_attr[mode]) cmds.setAttr(i + user_attr[mode], value)
def UpdateImagePlane(imagePlaneName, cameraName, updateSize = True): print "Updating image planes" def BreakPreviousConnection(): for i in cmds.ls(cameras = True): ConnectedPlanes = cmds.listConnections( i + ".imagePlane" , c = True) if ConnectedPlanes != None: for j in range(len(ConnectedPlanes)): if ConnectedPlanes[j] == imagePlaneName: try: cmds.disconnectAttr(imagePlaneName + "Shape.message", ConnectedPlanes[j-1]) except: print "Not Connected" return BreakPreviousConnection() try: mel.eval( 'cameraImagePlaneUpdate "%s" "%s";' % (cameraName + "Shape", imagePlaneName + "Shape") ) except: pass try: cmds.parent(imagePlaneName,cameraName) except: pass cmds.setAttr(imagePlaneName +".translateX", 0) cmds.setAttr(imagePlaneName +".translateY", 0) cmds.setAttr(imagePlaneName +".translateZ", -1) cmds.setAttr(imagePlaneName +".rotateX", 0 ) cmds.setAttr(imagePlaneName +".rotateY", 0 ) cmds.setAttr(imagePlaneName +".rotateZ", 0 ) cmds.setAttr(imagePlaneName +".scaleX", 0 ) cmds.setAttr(imagePlaneName +".scaleY", 0 ) cmds.setAttr(imagePlaneName +".scaleZ", 0 ) if updateSize: subLayers = ["Subdivision_0", "Subdivision_1"] for i in range(0,len(subLayers)): cmds.editRenderLayerGlobals( currentRenderLayer = subLayers[i]) cmds.editRenderLayerAdjustment(imagePlaneName + ".sizeX") cmds.editRenderLayerAdjustment(imagePlaneName + ".sizeY") cmds.setAttr(imagePlaneName + ".sizeX", 0.435) cmds.setAttr(imagePlaneName + ".sizeY", 0.035) cmds.editRenderLayerGlobals( currentRenderLayer = "defaultRenderLayer") cmds.setAttr(imagePlaneName + ".sizeX", 0.0) cmds.setAttr(imagePlaneName + ".sizeY", 0.0) print "Updated imageplanes"
def main(layer_name): layer_adjustments = cmds.editRenderLayerAdjustment(layer_name, query=True, layer=True) for adj in layer_adjustments: val = cmds.getAttr(adj) print adj + " = " + val
def checkOverride(self): self.layer=pm.editRenderLayerGlobals( query=True, currentRenderLayer=True ) if self.layer!='defaultRenderLayer': override_list=cmds.editRenderLayerAdjustment( self.layer,layer=True,q=True) if override_list != None: if self.attr in override_list: self.label.setStyleSheet("color: rgb(255, 127, 0);")
def SundayRenderToolsExportRenderLayer(): exportLayers = { } RL = mel.eval('getSelectedRenderItems("RenderLayerTab", "", 0);') for curRL in RL: if curRL != 'defaultRenderLayer': rl = { } rl['objects'] = cmds.editRenderLayerMembers(curRL, query = True) adj = cmds.editRenderLayerAdjustment(curRL, query = True, layer = True) adjustments = { } if adj != None: for curAdj in adj: adjustments[curAdj] = cmds.getAttr(curAdj) rl['adjustments'] = adjustments settings = { } settings['renderable'] = cmds.getAttr(curRL + '.renderable') rl['settings'] = settings exportLayers[curRL] = rl continue print 'Default layer can not be exported' file = SundayDialogPy.SundayDialogFileOpen('/', 0, 'Nothing!!') if file == None: return None f = open(file[0] + '.rl', 'w') f.write(str(exportLayers)) f.close()
def redshift_on_off(self, obj_name, cmd, value, *argv): print obj_name, cmd, value if cmd == 'rsMatteEnable': try: cmds.editRenderLayerAdjustment( '{}.{}'.format(obj_name, cmd), '{}.rsMatteAlpha'.format(obj_name)) cmds.setAttr('{}.{}'.format(obj_name, cmd), value) cmds.setAttr(obj_name + ".rsMatteAlpha", 0) except: pass else: try: cmds.setAttr('{}.{}'.format(obj_name, cmd), value) except: pass
def removeShaderOverride(self): """docstring for fname""" sel = mn.ls( sl = True ) rlay = rlayer.current() if not sel: rlay.removeOverridedShader() else: with undo.Undo(): for s in sel: childs = s.allchildren if childs: for c in childs: shap = c.shape if shap: mc.editRenderLayerAdjustment( shap.name + '.instObjGroups', remove = True ) shap = s.shape if shap: mc.editRenderLayerAdjustment( shap.name + '.instObjGroups', remove = True )
def on_checkBox_RPMMATL_clicked(self): """ Slot documentation goes here. """ if self.checkBox_RPMMATL.isChecked() == True: cmds.select(cmds.ls(type="RedshiftProxyMesh")) ALLProxyMeshLIST = cmds.ls(sl=1) for esy in ALLProxyMeshLIST: cmds.editRenderLayerAdjustment(str(esy) + ".materialMode") cmds.select(ALLProxyMeshLIST) print ("Create Layer Override") else: cmds.select(cmds.ls(type="RedshiftProxyMesh")) ALLProxyMeshLIST = cmds.ls(sl=1) for esy in ALLProxyMeshLIST: cmds.editRenderLayerAdjustment(str(esy) + ".materialMode", remove=1) cmds.select(ALLProxyMeshLIST) print ("Remove Layer Override")
def dpaf_removeCamOverride(self, allLayer, *args): camerAdjList = cmds.textScrollList('af_cameraScr', q= 1, si= 1) if camerAdjList: for cam in camerAdjList: cmaShapeAttr = cmds.listRelatives(cam, s= 1)[0] + '.renderable' if allLayer: for layer in cmds.listConnections(cmaShapeAttr, p= 1): layer = layer.split('.')[0] if layer != 'defaultRenderLayer': cmds.editRenderLayerAdjustment(cmaShapeAttr, lyr= layer, r= 1) else: layer = cmds.optionMenu('af_layerMenu', q= 1, v= 1) if layer == 'No Renderable Layer' or layer.startswith('-'): layer = 'masterLayer' if layer != 'masterLayer': cmds.editRenderLayerAdjustment(cmaShapeAttr, lyr= layer, r= 1) self.dpaf_getCameraList()
def change_render_settings(): """changes mental ray render settings to appropriate defaults""" # switch to mental ray rendering cmds.setAttr('defaultRenderGlobals.ren', 'mentalRay', type='string') # create the mental ray rendering nodes so they can be changed mel.eval('miCreateDefaultNodes') # set filter to gaussian as layer overide cmds.editRenderLayerAdjustment( 'miDefaultOptions.filter', layer='ao' ) cmds.setAttr('miDefaultOptions.filter', 2); # set the max/min samples cmds.setAttr('miDefaultOptions.maxSamples', 2) cmds.setAttr('miDefaultOptions.minSamples', 0) mel.eval('setAttr "miDefaultOptions.rayTracing" 0;') mel.eval('setAttr "defaultRenderGlobals.imageFormat" 3;') mel.eval('setAttr "miDefaultFramebuffer.datatype" 16;') mel.eval('setAttr "defaultResolution.width" 640;') mel.eval('setAttr "defaultResolution.height" 480;') mel.eval('setAttr "defaultResolution.pixelAspect" 1;')
def jpmMakeLayer(name): allLayers = cmds.ls(et="renderLayer") layerExists = 0 for layer in allLayers: if name == layer: layerExists = 1 if not layerExists: cmds.createRenderLayer(name=name, number=1, empty=1, mc=1) cmds.editRenderLayerAdjustment("defaultRenderGlobals.imageFilePrefix", lyr=name) cmds.setAttr("defaultRenderGlobals.imageFilePrefix", name, type="string") cmds.setAttr((name + ".renderable"), 0) print("Layer " + name + " made\n") else: print("Layer " + name + " already exists")
def dpaf_hasOverride(self, queryValue, queryLayer): # checking value has overrided or not attrList = cmds.editRenderLayerAdjustment(queryLayer, q= 1, lyr= 1) has = 0 if attrList: for attr in attrList: if attr == queryValue: has = 1 break return has
def get_master_layer_value(aov_name): """ Get the aov enabled state of an aov on the master render layer :param aov_name: the aov name as a string :return: the enabled value as a bool """ current_layer = cmds.editRenderLayerGlobals(currentRenderLayer=True, query=True) # If we are in the master layer return the current value if current_layer == "defaultRenderLayer": return cmds.getAttr("%s.enabled" % aov_name) # If we are not in the master layer check if the layer has an override layer_overrides = cmds.listConnections('%s.enabled' % aov_name) or [] # If there is not an override for this layer return the curr value if current_layer not in layer_overrides: return cmds.getAttr("%s.enabled" % aov_name) # If the layer has an override # Query the override value layer_value = cmds.getAttr("%s.enabled" % aov_name) # Remove the override cmds.editRenderLayerAdjustment("%s.enabled" % aov_name, layer=current_layer, remove=True) # Get the master value master_value = cmds.getAttr("%s.enabled" % aov_name) # Reinstate the override cmds.editRenderLayerAdjustment("%s.enabled" % aov_name, layer=current_layer) # Set the override value cmds.setAttr("%s.enabled" % aov_name, layer_value) return master_value
def connectPreview(): nodes = getRegionNode() if len(nodes) > 1: for node in nodes: renderlayer = cmds.listConnections(node + '.renderlayer')[0] if renderlayer != 'defaultRenderLayer': cmds.editRenderLayerAdjustment('defaultRenderGlobals.left', 'defaultRenderGlobals.rght', 'defaultRenderGlobals.bot', 'defaultRenderGlobals.top', layer=renderlayer) for node in nodes: #activating renderlayer renderlayer = cmds.listConnections(node + '.renderlayer')[0] cmds.editRenderLayerGlobals(currentRenderLayer=renderlayer) cmds.refresh() #create container container = cmds.container(n=node + '_previewConnection') cmds.addAttr(container, ln='minX', defaultValue=1) cmds.addAttr(container, ln='minY', defaultValue=1) #connect to preview cmds.connectAttr(node + '.minX', container + '.minX') cmds.connectAttr(container + '.minX', 'defaultRenderGlobals.left') cmds.connectAttr(node + '.minY', container + '.minY') cmds.connectAttr(container + '.minY', 'defaultRenderGlobals.bot') [clp, pms] = clampMax(node + '.maxX', node + '.renderwidth', 'defaultRenderGlobals.rght') cmds.container(container, e=True, addNode=[clp, pms]) [clp, pms] = clampMax(node + '.maxY', node + '.renderheight', 'defaultRenderGlobals.top') cmds.container(container, e=True, addNode=[clp, pms])
def defineBeautyLayer(layerName,passes,globalOverrides=1,*args): # GIven a layer name and an array of passes, create the passes and enable them as an override on that layer. # also enable lights, GI, etc if necessary passList = [] cmds.editRenderLayerGlobals(crl='defaultRenderLayer') # global overrides if globalOverrides: cmds.setAttr('vraySettings.globopt_light_doLights',0) cmds.setAttr('vraySettings.globopt_mtl_glossy',0) cmds.setAttr('vraySettings.cam_overrideEnvtex',0) cmds.setAttr('vraySettings.giOn',0) for p in passes: # check for duplicate elements = [cmds.getAttr(f+'.vrayClassType') for f in cmds.ls(type='VRayRenderElement')] extraTexes = [f for f in cmds.ls(type='VRayRenderElement') if cmds.getAttr(f+'.vrayClassType') == 'ExtraTexElement'] extraTexNames = [cmds.getAttr(f+'.vray_name_extratex') for f in extraTexes] if (parseElementNames(p) not in elements) or (parseElementNames(p) == 'ExtraTexElement' and p not in extraTexNames): melCmd = 'vrayAddRenderElement '+parseElementNames(p) mel.eval(melCmd) # get new pass by loading selection newPass = cmds.ls(sl=1)[0] passList.append(newPass) cmds.setAttr(newPass+'.enabled',0) # now go through passList and make an override for the beauty layer. cmds.editRenderLayerGlobals(crl=layerName) cmds.editRenderLayerGlobals(eaa=1) for p in passList: cmds.editRenderLayerAdjustment(p+'.enabled') cmds.setAttr(p+'.enabled',1) # global overrides if globalOverrides: cmds.editRenderLayerAdjustment('vraySettings.globopt_light_doLights') cmds.editRenderLayerAdjustment('vraySettings.globopt_mtl_glossy') cmds.editRenderLayerAdjustment('vraySettings.cam_overrideEnvtex') cmds.setAttr('vraySettings.globopt_light_doLights',1) cmds.setAttr('vraySettings.globopt_mtl_glossy',1) cmds.setAttr('vraySettings.cam_overrideEnvtex',1) if 'GI' in passes: cmds.editRenderLayerAdjustment('vraySettings.giOn') cmds.setAttr('vraySettings.giOn',1) # done. print '\nBeauty layer settings applied to layer %s.' % (layerName)
def connectPreview(): nodes=getRegionNode() if len(nodes)>1: for node in nodes: renderlayer=cmds.listConnections(node+'.renderlayer')[0] if renderlayer!='defaultRenderLayer': cmds.editRenderLayerAdjustment( 'defaultRenderGlobals.left', 'defaultRenderGlobals.rght', 'defaultRenderGlobals.bot', 'defaultRenderGlobals.top', layer=renderlayer ) for node in nodes: #activating renderlayer renderlayer=cmds.listConnections(node+'.renderlayer')[0] cmds.editRenderLayerGlobals( currentRenderLayer=renderlayer) cmds.refresh() #create container container=cmds.container(n=node+'_previewConnection') cmds.addAttr(container,ln='minX',defaultValue=1) cmds.addAttr(container,ln='minY',defaultValue=1) #connect to preview cmds.connectAttr(node+'.minX',container+'.minX') cmds.connectAttr(container+'.minX','defaultRenderGlobals.left') cmds.connectAttr(node+'.minY',container+'.minY') cmds.connectAttr(container+'.minY','defaultRenderGlobals.bot') [clp,pms]=clampMax(node+'.maxX',node+'.renderwidth','defaultRenderGlobals.rght') cmds.container(container,e=True,addNode=[clp,pms]) [clp,pms]=clampMax(node+'.maxY',node+'.renderheight','defaultRenderGlobals.top') cmds.container(container,e=True,addNode=[clp,pms])
def batchLayers( button ): renderLayers = getRenderLayers() allRenderLayers = [] for layer in renderLayers: if (layer != 'defaultRenderLayer'): allRenderLayers.append(layer) renderElements = getVrayRenderElements() selectedSceneRE = vraySelectedSceneRE() condition = 0 warningTxt = '' if (selectedSceneRE == None): if ( button == 'add'): condition = 1 warningTxt = 'All Vray Render elements have been enabled in All render layers.' if (button == 'remove'): condition = 0 warningTxt = 'All Vray Render elements have been disable in All render layers.' for x in allRenderLayers: cmds.editRenderLayerGlobals(currentRenderLayer = x, eaa = True) for y in renderElements: attr = (y + '.enabled') cmds.editRenderLayerAdjustment(attr) cmds.setAttr(attr, condition); print (attr + ' '+str(condition)) else: if ( button == 'add'): condition = 1 warningTxt = 'Selected Vray Render elements have been enabled in All render layers.' if (button == 'remove'): condition = 0 warningTxt = 'Selected Vray Render elements have been disable in All render layers.' for x in allRenderLayers: cmds.editRenderLayerGlobals(currentRenderLayer = x, eaa = True) for y in selectedSceneRE: attr = (y + '.enabled') cmds.editRenderLayerAdjustment(attr) cmds.setAttr(attr, condition) print (attr + ' '+str(condition)) vrayUpdateUI() cmds.warning(warningTxt)
def set_attr_in_layer(attr=None, layer=None, value=None): """ Same as cmds.setAttr but this sets the attribute's value in a given render layer without having to switch to it :param attr: string - ex: "node.attribute" :param layer: string - ex: "layer_name" :param value: value you want to set the override to :return: bool - True if successful, False if not """ cmds.editRenderLayerAdjustment(attr, layer=layer) connection_list = cmds.listConnections(attr, plugs=True) if connection_list is not None: for connection in connection_list: attr_component_list = connection.split(".") if attr_component_list[0] == layer: attr = ".".join(attr_component_list[0:-1]) cmds.setAttr("%s.value" % attr, value) return True return False
def _disable_aov_for_all_layers_callback(self): """ Callback for disabling an aov for all the render layers :return: """ selected_items = self.layers_tree.selectedItems() if selected_items is None: return selected_aovs = [ x for x in selected_items if x.data(0, QtCore.Qt.UserRole) == "aov" ] or None if selected_aovs is None: return render_layers = [ x for x in cmds.ls(type="renderLayer") if "defaultRenderLayer" not in x ] for aov_item in selected_aovs: aov_name = aov_item.data(1, QtCore.Qt.UserRole) # Remove aov layer override for all layers for rLayer in render_layers: cmds.editRenderLayerAdjustment("%s.enabled" % aov_name, layer=rLayer, remove=True) # Set the Aov as disabled cmds.setAttr("%s.enabled" % aov_name, 0) self._refresh_layers_content() return
def SundayRenderToolsImportRenderLayer(): file = SundayDialogPy.SundayDialogFileOpen('/', 1, 'Render Layer File (*.rl)') if file == None: return None f = open(file[0], 'r') iL = eval(f.read()) for curIL in iL: cmds.createRenderLayer(name = curIL, empty = True) addObj = iL[curIL]['objects'] try: cmds.editRenderLayerMembers(curIL, addObj, noRecurse = True) except: file == None print 'Objects not found in scene' addAdj = iL[curIL]['adjustments'] cmds.editRenderLayerGlobals(currentRenderLayer = curIL) for curAdj in addAdj: if curAdj.split('.')[1] != 'instObjGroups[0]': cmds.editRenderLayerAdjustment(curIL, curAdj) try: cmds.setAttr(curAdj, addAdj[curAdj]) except: pass print 'Missing : ' + curAdj continue print 'Shader Overwrite : ' + curAdj addSet = iL[curIL]['settings'] for curSet in addSet: if curSet == 'renderable': cmds.setAttr(curIL + '.renderable', addSet[curSet]) continue
def bNormal(*args): t = "NRM" sels = cmds.ls(sl=True) if type(args[0]) == types.StringType: name = get_name(args[0]+"_"+t) else : name = get_name(t) if not(cmds.objExists(name)) : sf = int(cmds.textFieldGrp('start_frame', q=True, tx=True)) ef = int(cmds.textFieldGrp('end_frame', q=True, tx=True)) make_layer(name, sf, ef, t) rl = make_layer(name, sf, ef, t) cmds.editRenderLayerGlobals(crl= rl[0]) cmds.setAttr("defaultRenderGlobals.ren", "vray", typ='string') v_ray_set() mel.eval("vrayAddRenderElement normalsChannel;") cmds.editRenderLayerAdjustment("vraySettings.fileNamePrefix") cmds.setAttr("vraySettings.fileNamePrefix", rl[0],typ="string") #cmds.editRenderLayerAdjustment("vraySettings.noAlpha") cmds.editRenderLayerAdjustment("vraySettings.dontSaveRgbChannel") #cmds.setAttr("vraySettings.noAlpha",1) cmds.setAttr("vraySettings.dontSaveRgbChannel",1) if len(sels) != 0 : cmds.select(sels,r=True) return name
def list(): """ Output layer overrides for the current layer. """ layer = mc.editRenderLayerGlobals(query=True, currentRenderLayer=True) adjustments = mc.editRenderLayerAdjustment(layer, query=True, layer=True) print("\n*** List of overrides for layer '%s:' ***" % layer) if adjustments: for adj in adjustments: print("%s = %s" % (adj, mc.getAttr(adj))) else: print("None") print("\n")
def assignTurntable(Camera): #Works differently from the snapshots since they don't have the distinction of signature #Get the name for the turntable layer RenderLayer = "Turntable" + Camera[-1] #Create a new render layer for the turntable cmds.createRenderLayer( n = RenderLayer, g = True ) RenderLayerManagerClass.EditLayer(settings = [ [Camera + ".renderable", "none", True ], ["persp.renderable", "none", False ], ["defaultRenderGlobals.animation", "none", True], ["defaultRenderGlobals.startFrame", "none", cmds.getAttr(Camera + ".StartRange")], ["defaultRenderGlobals.endFrame", "none", cmds.getAttr(Camera + ".StopRange")], ["defaultRenderGlobals.outFormatControl", "none", 0], ["defaultRenderGlobals.putFrameBeforeExt", "none", 1], ["defaultRenderGlobals.periodInExt ", "none", 0], ["defaultRenderGlobals.imageFilePrefix", "string", "<Camera>/<Scene>_<Layer>_"], ["defaultRenderGlobals.extensionPadding", "none", 2] ], layers = [RenderLayer] ) cmds.editRenderLayerGlobals( currentRenderLayer = RenderLayer) #If background objects exist render the turntable with the background else use the shadow plane if it exists if cmds.objExists("CMBackground"): cmds.editRenderLayerAdjustment("CMBackground.visibility") cmds.setAttr("CMBackground.visibility", 1) if cmds.objExists("ShadowPlane"): cmds.editRenderLayerAdjustment("ShadowPlane.visibility") cmds.setAttr("ShadowPlane.visibility", 0) #If userlights and light rig exist use the userlights for the turntable if cmds.objExists("UserLights") and cmds.objExists("CMLightRig"): cmds.editRenderLayerAdjustment("UserLights.visibility") cmds.setAttr("UserLights.visibility", 1) cmds.editRenderLayerAdjustment("CMLightRig.visibility") cmds.setAttr("CMLightRig.visibility", 0) RenderLayerManagerClass.EditLayer(settings = [["vraySettings.fileNamePrefix", "string", "<Camera>/<Scene>_<Layer>_"]], layers = [RenderLayer] )
def createRL(*args): layers = [] rls = [ "CarKey", "CarEnv", "BGKey", "BGEnv", "AO", "MatteA", "MatteB", "MoVec", "Shadow" ] movecShd = cmds.ls("*:*moVec_SHD") if not movecShd: movecShd = cmds.ls("*moVec_SHD") if movecShd: mvsg = cmds.listConnections(movecShd, type="shadingEngine")[0] else: cmds.warning("Can't find the movec shader") aoShd = cmds.ls("*:*AO_SHD") if not aoShd: aoShd = cmds.ls("*AO_SHD") if aoShd: aosg = cmds.listConnections(aoShd, type="shadingEngine")[0] else: cmds.warning("can't find the ao shader") for rl in rls: if cmds.checkBox(widgets[rl], q=True, v=True): layers.append(rl) for each in layers: cmds.createRenderLayer(n=renderLayer[each], mc=True, empty=True) if each == "MoVec": cmds.editRenderLayerAdjustment( 'defaultArnoldRenderOptions.motion_blur_enable', lyr="ALL_MoVec") cmds.setAttr("defaultArnoldRenderOptions.motion_blur_enable", 1) cmds.editRenderLayerAdjustment( "defaultArnoldRenderOptions.referenceTime", lyr="ALL_MoVec") cmds.setAttr("defaultArnoldRenderOptions.referenceTime", 0.5) cmds.editRenderLayerAdjustment( "defaultArnoldRenderOptions.ignoreMotionBlur", lyr="ALL_MoVec") cmds.setAttr("defaultArnoldRenderOptions.ignoreMotionBlur", 1) print mvsg if mvsg: cmds.connectAttr("%s.message" % mvsg, "ALL_MoVec.shadingGroupOverride", f=True) if each == "AO": print aosg if aosg: cmds.connectAttr("%s.message" % aosg, "ALL_AO.shadingGroupOverride", f=True)
def overrideTransfer(layerName): sourceObjSplit = sourceObj[0].split("|") sourceShapeSplit = sourceShape[0].split("|") rawOverrides = mc.editRenderLayerAdjustment(layerName, query=True, layer=True ) allOverrides = [] if layerName == "defaultRenderLayer": pass else: if rawOverrides == None: pass else: for x in rawOverrides: if "instObjGroup" in x: pass elif x in allOverrides: pass else: allOverrides.append(x) for eachOverride in allOverrides: attrName=eachOverride.split(".") # match transform node overrides srcObjAttrCheck = mc.attributeQuery(attrName[-1],node=sourceObj[0],ex=True) if srcObjAttrCheck == True: if sourceObjSplit[-1]+"."+attrName[-1] in eachOverride: for eachTarget in targetObjs: mc.editRenderLayerAdjustment(eachTarget+"."+attrName[-1]) mc.copyAttr(sourceObj,eachTarget,values=True,attribute=[attrName[-1]]) # match shape node overrides srcShapeAttrCheck = mc.attributeQuery(attrName[-1],node=sourceShape[0],ex=True) if srcShapeAttrCheck == True: if sourceShapeSplit[-1]+"."+attrName[-1] in eachOverride: attrType = mc.getAttr(eachOverride,type=True) if "float3" in attrType: valueX = mc.getAttr(sourceShape[0]+"."+attrName[-1]+"X") valueY = mc.getAttr(sourceShape[0]+"."+attrName[-1]+"Y") valueZ = mc.getAttr(sourceShape[0]+"."+attrName[-1]+"Z") for eachShape in targetShapes: mc.editRenderLayerAdjustment(eachShape+"."+attrName[-1]) mc.setAttr(eachShape+"."+attrName[-1]+"X",valueX) mc.setAttr(eachShape+"."+attrName[-1]+"Y",valueY) mc.setAttr(eachShape+"."+attrName[-1]+"Z",valueZ) else: value = mc.getAttr(sourceShape[0]+"."+attrName[-1]) for eachShape in targetShapes: mc.editRenderLayerAdjustment(eachShape+"."+attrName[-1]) mc.setAttr(eachShape+"."+attrName[-1],value)
def ManageUserRig(): cmds.editRenderLayerGlobals( currentRenderLayer = "defaultRenderLayer") #If the background exists make sure it is not visible in any layer except the product shots else use the shadow plane if it exists if cmds.objExists("CMBackground"): cmds.setAttr("CMBackground.visibility", 0) if cmds.objExists("ShadowPlane"): cmds.setAttr("ShadowPlane.visibility", 1) #If userlights exist and lightrig exists make the userlights invisible in all except the product shot and contex sig if cmds.objExists("UserLights") and cmds.objExists("CMLightRig"): cmds.setAttr("UserLights.visibility", 0) cmds.setAttr("CMLightRig.visibility", 1) #Modify the productshot and contextsig attributes layers = ["Product", "ContextSig"] i = 0 while(cmds.objExists("Turntable" + str(i))): layers.append("Turntable" + str(i)) i = i + 1 for i in layers: cmds.editRenderLayerGlobals( currentRenderLayer = i) #If background objects exist render the product shot with the background else use the shadow plane if it exists if cmds.objExists("CMBackground"): cmds.editRenderLayerAdjustment("CMBackground.visibility") cmds.setAttr("CMBackground.visibility", 1) if cmds.objExists("ShadowPlane"): cmds.editRenderLayerAdjustment("ShadowPlane.visibility") cmds.setAttr("ShadowPlane.visibility", 0) #If userlights and light rig exist use the userlights for the product shots and render the rest with the light rig if cmds.objExists("UserLights") and cmds.objExists("CMLightRig"): cmds.editRenderLayerAdjustment("UserLights.visibility") cmds.setAttr("UserLights.visibility", 1) cmds.editRenderLayerAdjustment("CMLightRig.visibility") cmds.setAttr("CMLightRig.visibility", 0) cmds.editRenderLayerGlobals( currentRenderLayer = "defaultRenderLayer")
def EditLayer(settings, layers, ChangeRenderLayer = True): for layer in layers: if ChangeRenderLayer: cmds.editRenderLayerGlobals( currentRenderLayer = layer) for i in settings: if i[1] == "RemoveFromLayer": cmds.editRenderLayerAdjustment(i[0], remove = True) else: try: if i[1] == "double3": cmds.editRenderLayerAdjustment(i[0]) cmds.setAttr(i[0], i[2], i[3], i[4], type = i[1] ) elif i[1] == "string": cmds.editRenderLayerAdjustment(i[0]) cmds.setAttr( i[0], i[2], type = i[1] ) elif i[1] == "none": cmds.editRenderLayerAdjustment(i[0]) cmds.setAttr( i[0], i[2] ) except: pass if ChangeRenderLayer: cmds.editRenderLayerGlobals( currentRenderLayer = "defaultRenderLayer")
def make_layer(name,sf,ef, r_type): rl_name = name sels = cmds.ls(sl=True) r_cam = cmds.textScrollList('r_cam', q=True, si=True) cs = lambda x:cmds.listRelatives(x,shapes=True) #check object exist if not(cmds.objExists(name)): l = cmds.createRenderLayer(n=rl_name, number=2,noRecurse=True) drg = "defaultRenderGlobals" cmds.editRenderLayerGlobals(crl=l) cmds.editRenderLayerAdjustment("defaultRenderGlobals.imageFilePrefix") cmds.editRenderLayerAdjustment("defaultRenderGlobals.imageFormat") cmds.editRenderLayerAdjustment(drg+".currentRenderer") cmds.setAttr(drg+".ren","mayaSoftware",typ="string") cmds.setAttr(drg+".imageFilePrefix",rl_name,typ="string") cmds.setAttr(drg+".imageFormat",32) cmds.setAttr(drg + ".startFrame", sf) cmds.setAttr(drg + ".endFrame", ef) else: l = rl_name put_obj(sels,rl_name) # Collect Camera data a_cam = cm_list() a_cam = a_cam[0] # All camera's renderable attribute is OFF. for ac in a_cam: cmds.setAttr(ac+".renderable", 0) # Turn on "renderble" : selected camera. cam = [] if not(type(r_cam) == types.NoneType): for rc in r_cam: x = cs(rc) cmds.setAttr(x[0]+".renderable", 1) cam.append(x) return (l,cam)
def createRL(*args): layers = [] rls = ["CarKey", "CarEnv", "BGKey", "BGEnv", "AO", "MatteA", "MatteB", "MoVec", "Shadow"] movecShd = cmds.ls("*:*moVec_SHD") if not movecShd: movecShd = cmds.ls("*moVec_SHD") if movecShd: mvsg = cmds.listConnections(movecShd, type="shadingEngine")[0] else: cmds.warning("Can't find the movec shader") aoShd = cmds.ls("*:*AO_SHD") if not aoShd: aoShd = cmds.ls("*AO_SHD") if aoShd: aosg = cmds.listConnections(aoShd, type="shadingEngine")[0] else: cmds.warning("can't find the ao shader") for rl in rls: if cmds.checkBox(widgets[rl], q=True, v=True): layers.append(rl) for each in layers: cmds.createRenderLayer(n=renderLayer[each], mc=True, empty=True) if each == "MoVec": cmds.editRenderLayerAdjustment('defaultArnoldRenderOptions.motion_blur_enable', lyr="ALL_MoVec") cmds.setAttr("defaultArnoldRenderOptions.motion_blur_enable", 1) cmds.editRenderLayerAdjustment("defaultArnoldRenderOptions.referenceTime", lyr="ALL_MoVec") cmds.setAttr("defaultArnoldRenderOptions.referenceTime", 0.5) cmds.editRenderLayerAdjustment("defaultArnoldRenderOptions.ignoreMotionBlur", lyr="ALL_MoVec") cmds.setAttr("defaultArnoldRenderOptions.ignoreMotionBlur", 1) print mvsg if mvsg: cmds.connectAttr("%s.message"%mvsg, "ALL_MoVec.shadingGroupOverride", f=True) if each == "AO": print aosg if aosg: cmds.connectAttr("%s.message"%aosg, "ALL_AO.shadingGroupOverride", f=True)
def make_layer(n,cus,sw,sf,ef, r_type): rl_name= "" if sw: rl_name = cus else: rl_name = n l = cmds.createRenderLayer(n=rl_name, number=2,noRecurse=True) cmds.editRenderLayerGlobals(crl=l) cmds.editRenderLayerAdjustment("defaultRenderGlobals.imageFilePrefix") cmds.editRenderLayerAdjustment("defaultRenderGlobals.imageFormat") drg = "defaultRenderGlobals" cmds.setAttr(drg+".imageFilePrefix",rl_name,typ="string") cmds.setAttr(drg+".imageFormat",32) cmds.setAttr(drg + ".startFrame", sf) cmds.setAttr(drg + ".endFrame", ef) if (r_type == "AO"): cmds.editRenderLayerAdjustment(drg+".currentRenderer") cmds.setAttr(drg+".ren","mentalRay",typ="string") return l
def setupScene(): global util errormsgs = [] util = Utils.utils() chks = ['keychk', 'rimchk','colchk','occchk','rgbachk','gshchk','matchk'] chkstats = [mc.checkBox(x, q = True, v = True) for x in chks] if not 1 in chkstats: mc.confirmDialog(t='Warning', m = 'No layers are selected', b='OK', ma = "center") return #get dict of assets in their respective render layer groups grpDict = findGrpDict() layergrps = grpDict.keys() layergrps.sort() #find the path of the file, check naming of file and query the timeline filepath = mc.file(q = True, sn = True) filename = os.path.basename(filepath) fildir = os.path.dirname(filepath) refcut = mc.checkBox("refchk", q = True, v = True) try: shotname = filename.split("_")[1] except: mc.confirmDialog(t='Warning', m = 'Scene name is not correct', b='OK', ma = "center") return shstart = mc.playbackOptions(q = True, ast = True) shend = mc.playbackOptions(q = True, aet = True) #query the camera and the camera group cam = mc.optionMenu('camlite', q = True, v = True) #setup the name of the new files clfile = filename[:-9] + "cl" + filename[-7:] #check the file exists, then change to vesion folder curr_path = fildir+'/' clfilepath=curr_path+clfile if mc.file(clfilepath,q=1,ex=1): Overrite = mc.confirmDialog( title='Confirm ', message='Overwrite the existing file? ', button=['Yes', 'No'], defaultButton='Yes', cancelButton='No', dismissString='No') if Overrite =='No': return chkpath=mc.getFileList (folder=curr_path) ver_count=chkpath.count('ver') verpath= curr_path+'ver/' if not ver_count: mc.sysFile(verpath,makeDir=1) # else: # verpath= curr_path+'ver/' files = [ f for f in os.listdir(verpath) if (os.path.isfile (os.path.join(verpath,f))) and f[len(f)-3:len(f)]=='.ma'] if files: ver = str(len(files)+1) else: ver='01' newpath=verpath+clfile mc.sysFile(filepath,copy=newpath) newname=clfile[:19]+'%s.ma'%ver.zfill(2) chgname=verpath+newname mc.sysFile(newpath,rename=chgname) #select all the assets specified in the setup window to export to a new file selasts = [] refcutmiss = [] for each in layergrps: for ast in grpDict[each]: selasts.append(ast) #add the camera to the selection selasts.append(cam) #add the ground and matte groups to the selection if they exist, else warn that they have not been setup gndmteobjs = ["Grp_Ground", "Grp_Matte"] if mc.objExists("Grp_Ground"): gndmteobjs.pop(gndmteobjs.index("Grp_Ground")) selasts.append("Grp_Ground") if mc.objExists("Grp_Matte"): gndmteobjs.pop(gndmteobjs.index("Grp_Matte")) selasts.append("Grp_Matte") if gndmteobjs: gndmtemsg = "\n".join(gndmteobjs) rslt = mc.confirmDialog(t='Warning', m="Ground/Matte Objects dont\nexist or havent been set up", b=['Continue', 'Cancel'], db='Continue', cb='Cancel', ds='Cancel', ma = 'center') if rslt == 'Cancel': return else: pass mc.select(selasts, r = True) #cmfile = filename[:-9] + "cm" + filename[-7:] #export all selected assets, cameras and ground/matte groups to a new _cl_v00 file mc.file((fildir + "/" + clfile), op = "v=0", typ = "mayaAscii", pr = True, es = True, f=True ) #force open the new _cl_v00 file without saving the old one mc.file((fildir + "/" + clfile), op = "v=0", typ = "mayaAscii", lrd = "all", o = True, f = True) #select camera and export selected camera to a new _cm_v00 file #mc.select(cam, r = True) #mc.file((fildir + "/" + cmfile), op = "v=0", typ = "mayaAscii", pr = True, es = True) mc.select(cl = True) #set the timeline and render globals, and move assets to their respective groups mc.playbackOptions(e = True, ast = shstart) mc.playbackOptions(e = True, aet = shend) setrendglobals(shotname, shstart, shend) try: Utils.moveAssetsToGrps() except: pass #setup the useBackground shader and assign it to the ground/matte objects if they exist gndusebg = "groundmatteuseBGshader" if mc.objExists(gndusebg): mc.delete(gndusebg) gndusebg = mc.shadingNode("useBackground", asShader = True, n = gndusebg) mc.setAttr((gndusebg + ".specularColor"), 0, 0, 0, type = "double3") mc.setAttr((gndusebg + ".reflectivity"), 0) mc.setAttr((gndusebg + ".reflectionLimit"), 0) mc.setAttr((gndusebg + ".shadowMask"), 0) if mc.objExists("Grp_Ground"): mc.select("Grp_Ground", r = True) mc.hyperShade(assign = gndusebg) if mc.objExists("Grp_Matte"): mc.select("Grp_Matte", r = True) mc.hyperShade(assign = gndusebg) #query the rim/key light required and import the relevant light file from /assets/lighting locquery = mc.optionMenu('Location', q = True, v = True) rmkylight = mc.optionMenu('Time', q = True, v = True) camquery = mc.optionMenu('camlite', q = True, v = True) rmkyfile = "%s/%s/Location/%s/%s_rimkey.ma"%(util.path, util.litePath,locquery,rmkylight) rimliteL = "%s:rimL"%rmkylight rimliteR = "%s:rimR"%rmkylight #refdoom = "%s:ref_doom"%rmkylight keylite = "%s:key"%rmkylight #fillite = "%s:fill"%rmkylight #eyespec = "%s:eyespc"%rmkylight if os.path.exists(rmkyfile): if mc.objExists(rimliteL): mc.delete(rimliteL) if mc.objExists(rimliteR): mc.delete(rimliteR) #if mc.objExists(fillite): #mc.delete(fillite) if mc.objExists(keylite): mc.delete(keylite) mc.file(rmkyfile, i = True, typ = "mayaAscii", ra = True, ns = rmkylight, op = "v=0;p=17", pr = True) else: mc.confirmDialog(t='Warning', m = '%s file is not accessible'%rmkylight, b='OK', ma = "center") return #find the names of the imported rim/key lights in the scene and parent them to the 'Rim_key' group if mc.objExists("LIGHTS"): mc.delete("LIGHTS") sclites = mc.ls(type = "light") for each in sclites: if ":rimL" in each: rimliteL = mc.listRelatives(each, p = True)[0] elif ":rimR" in each: rimliteR = mc.listRelatives(each, p = True)[0] #elif ":fill" in each: #fillite = mc.listRelatives(each, p = True)[0] elif ":key" in each: keylite = mc.listRelatives(each, p = True)[0] keygrp = "%s:key_set"%rmkylight mc.group(n = "LIGHTS", em = True) mc.parent(keygrp,"LIGHTS" ) #query common lights required and import the relevant light file from /assets/lighting/commonlights commonfile = "%s/%s/common_lights/common_lights.ma"%(util.path, util.litePath) commonlight="commonlight" #litequery=mc.optionMenu('amblite',q=True,v=True) #GIrAMB = "%s:%s"%(commonlight,litequery) if os.path.exists(commonfile): if mc.objExists(commonlight): mc.delete(commonlight) mc.file(commonfile, i = True, typ = "mayaAscii", ra = True, ns = commonlight, op = "v=0;p=17", pr = True) else: mc.confirmDialog(t='Warning', m = '%s file is not accessible'%commonlight, b='OK', ma = "center") return #mc.parent("commonlight:commonLight_sets","LIGHTS" ) #spclite_parnt=mc.parent(spclite,camquery) #find shape node of key light if mc.objExists(keylite): keyliteshp = mc.listRelatives(keylite, c = True, s = True) #setup the mat shaders rgbashaders = rgbashader(shotname) mc.select(cl = True) myShader = mc.shadingNode('lambert', asShader=True) mc.setAttr (myShader+".colorR", 0.886) mc.setAttr (myShader+".colorG" ,0.961) mc.setAttr (myShader+".colorB" ,0.961) # assign cam folder if camquery[14:] =='Ct': camname = "Center" elif camquery[14:]=='Lt': camname = "Left" else: camname = "Right" #remove all existing render layers mc.editRenderLayerGlobals(crl = "defaultRenderLayer") renlyrs = mc.ls(type = "renderLayer") for each in renlyrs: if not "defaultRenderLayer" in each: mc.delete(each) #cut the references of all assets if marked so in the light setup options for each in layergrps: for ast in grpDict[each]: if refcut: try: cutref(ast) except: refcutmiss.append(ast) #main loop for creating all the render layers with their respective settings working on each render layer group per loop sqname = shotname[:5] shname = shotname[5:] matindex = 0 for lyr in layergrps: asts = grpDict[lyr] #create key layer, add key light if mc.checkBox("keychk", q = True, v = True): keylayer = (lyr + 'key') mc.select(asts, r = True) mc.select(keylite, add = True) #mc.select(refdoom, add = True) #mc.select(eyespec, add = True) if mc.objExists("Grp_Ground"): mc.select("Grp_Ground", add = True) if mc.objExists("Grp_Matte"): mc.select("Grp_Matte", add = True) mc.createRenderLayer(mc = True, n = keylayer) mc.editRenderLayerAdjustment(gndusebg + ".shadowMask") mc.setAttr(gndusebg + ".miOcclusionMask", 0) mc.connectAttr(keylayer+'.renderPass', 'diff.owner',nextAvailable=True) mc.connectAttr(keylayer+'.renderPass', 'amb.owner', nextAvailable=True) mc.connectAttr(keylayer+'.renderPass', 'sha.owner', nextAvailable=True) mc.connectAttr(keylayer+'.renderPass', 'spc.owner', nextAvailable=True) mc.connectAttr(keylayer+'.renderPass', 'inc.owner',nextAvailable=True) fileprefix = "%s/%s/%s/ch/%s/<RenderLayer>/<RenderPass>/%s%s_<RenderLayer>_<RenderPass>_v01"%(sqname,shname,camname,lyr,sqname,shname) mc.editRenderLayerAdjustment ("defaultRenderGlobals.imageFilePrefix") mc.setAttr("defaultRenderGlobals.imageFilePrefix", fileprefix, type = "string") mc.editRenderLayerAdjustment('miDefaultOptions.rayTracing') mc.setAttr('miDefaultOptions.rayTracing',1) mc.editRenderLayerAdjustment( 'miDefaultOptions.maxReflectionRays' ) mc.setAttr('miDefaultOptions.maxReflectionRays', 3) mc.editRenderLayerAdjustment( 'miDefaultOptions.maxRefractionRays' ) mc.setAttr('miDefaultOptions.maxRefractionRays', 0) mc.editRenderLayerAdjustment( 'miDefaultOptions.maxRayDepth') mc.setAttr('miDefaultOptions.maxRayDepth',20) #create rim layer, add rimlight if mc.checkBox("rimchk", q = True, v = True): rimlayer = (lyr + 'rim') mc.select(asts, r = True) mc.select(rimliteL, add = True) mc.select(rimliteR, add = True) mc.createRenderLayer(mc = True, n = rimlayer) rimsh='%s:Rimshader'%commonlight #mc.shadingNode("lambert", asShader = True, n = rimsh ) #mc.setAttr((rimsh+'.color'),1, 1, 1, type = "double3") #mc.setAttr((rimsh+'.diffuse'),1) mc.select(rimsh) mel.eval('hookShaderOverride("%s","","%s")'%(rimlayer,rimsh)) fileprefix = "%s/%s/%s/ch/%s/<RenderLayer>/%s%s_<RenderLayer>_v01"%(sqname, shname,camname,lyr, sqname, shname) mc.editRenderLayerAdjustment ("defaultRenderGlobals.imageFilePrefix") mc.setAttr("defaultRenderGlobals.imageFilePrefix", fileprefix, type = "string") mc.editRenderLayerAdjustment('miDefaultOptions.rayTracing') mc.setAttr('miDefaultOptions.rayTracing',0) #create col layer,add amb light if mc.checkBox("colchk",q= True,v = True): collayer= (lyr+ 'col') mc.select(asts, r = True) Col_light='%s:colLight'%commonlight mc.select(Col_light,add=True) mc.createRenderLayer(mc = True, n = collayer) mc.editRenderLayerAdjustment ("defaultRenderGlobals.imageFilePrefix") mc.setAttr("defaultRenderGlobals.imageFilePrefix", fileprefix, type = "string") #create occ layer if mc.checkBox("occchk",q=True,v=True): occlayer = (lyr + 'occ') mc.select(asts,r=True) if mc.objExists("Grp_Ground"): mc.select("Grp_Ground", add = True) if mc.objExists("Grp_Matte"): mc.select("Grp_Matte", add = True) mc.createRenderLayer(mc = True, n = occlayer) mel.eval("renderLayerBuiltinPreset occlusion %s "%occlayer) ShaderList=mc.ls (sl=1) Mib_Amb=mc.listConnections(ShaderList,t='mib_amb_occlusion') mc.setAttr(Mib_Amb[0]+'.samples',64) mc.setAttr(Mib_Amb[0]+'.spread',0.8) mc.setAttr(Mib_Amb[0]+'.max_distance',20) fileprefix = "%s/%s/%s/ch/%s/<RenderLayer>/%s%s_<RenderLayer>_v01"%(sqname, shname,camname,lyr, sqname, shname) mc.editRenderLayerAdjustment ("defaultRenderGlobals.imageFilePrefix") mc.setAttr("defaultRenderGlobals.imageFilePrefix", fileprefix, type = "string") #create mat layer and assign r, g and b shaders in turn using matindex, turn off raytracing using layer override if mc.checkBox("rgbachk", q = True, v = True): rgbalayer = (lyr + 'rgba') mc.select(asts, r = True) mc.createRenderLayer(mc = True, n = rgbalayer) for i in range(len(asts)): shindex = matindex%4 matindex += 1 mc.select(asts[i], r = True) mc.hyperShade(assign = rgbashaders[shindex]) fileprefix = "%s/%s/%s/ch/%s/<RenderLayer>/%s%s_<RenderLayer>_v01"%(sqname, shname,camname,lyr, sqname, shname) mc.editRenderLayerAdjustment ("defaultRenderGlobals.imageFilePrefix") mc.setAttr("defaultRenderGlobals.imageFilePrefix", fileprefix, type = "string") mc.setAttr('miDefaultOptions.rayTracing',0) #create ground shadow layer, add key light and turn on shadow mask of useBG shader using layer override if mc.checkBox("gshchk", q = True, v = True): gshlayer = (lyr + 'gsh') mc.select(asts, r = True) mc.select(keylite, add = True) if mc.objExists("Grp_Ground"): mc.select("Grp_Ground", add = True) if mc.objExists("Grp_Matte"): mc.select("Grp_Matte", add = True) mc.createRenderLayer(mc = True, n = gshlayer) mc.editRenderLayerAdjustment(gndusebg + ".shadowMask") mc.setAttr(gndusebg + ".shadowMask", 1) fileprefix = "%s/%s/%s/ch/%s/<RenderLayer>/%s%s_<RenderLayer>_v01"%(sqname, shname,camname,lyr, sqname, shname) mc.editRenderLayerAdjustment ("defaultRenderGlobals.imageFilePrefix") mc.setAttr("defaultRenderGlobals.imageFilePrefix", fileprefix, type = "string") mc.editRenderLayerAdjustment('miDefaultOptions.rayTracing') mc.setAttr('miDefaultOptions.rayTracing',1) mc.editRenderLayerAdjustment( 'miDefaultOptions.maxReflectionRays' ) mc.setAttr('miDefaultOptions.maxReflectionRays', 0) mc.editRenderLayerAdjustment( 'miDefaultOptions.maxRefractionRays' ) mc.setAttr('miDefaultOptions.maxRefractionRays', 0) mc.editRenderLayerAdjustment( 'miDefaultOptions.maxRayDepth') mc.setAttr('miDefaultOptions.maxRayDepth',20) #turn off receive shadows and primary visibility of the all the assets using changespreadattr() for ast in asts: changespreadattr(ast, "receiveShadows", 0) changespreadattr(ast, "primaryVisibility", 0) #create mat layer if mc.checkBox("matchk",q= True, v = True): matlayer = (lyr + 'mat') mc.select(asts, r = True) Zdep='%s:Zdepthshader'%commonlight mc.select(asts, r = True) mc.createRenderLayer(mc = True, n = matlayer) mc.select(Zdep) mel.eval('hookShaderOverride("%s","","%s")'%(matlayer,Zdep)) mc.connectAttr(matlayer+'.renderPass', 'camnml.owner', nextAvailable=True) mc.connectAttr(matlayer+'.renderPass', 'nml.owner', nextAvailable=True) fileprefix = "%s/%s/%s/ch/%s/<RenderLayer>/<RenderPass>/%s%s_<RenderLayer>_<RenderPass>_v01"%(sqname,shname,camname,lyr,sqname,shname) mc.editRenderLayerAdjustment ("defaultRenderGlobals.imageFilePrefix") mc.setAttr("defaultRenderGlobals.imageFilePrefix", fileprefix, type = "string") mc.editRenderLayerAdjustment('miDefaultOptions.rayTracing') mc.setAttr('miDefaultOptions.rayTracing',0) mc.editRenderLayerAdjustment( 'miDefaultOptions.maxReflectionRays' ) mc.setAttr('miDefaultOptions.maxReflectionRays', 1) mc.editRenderLayerAdjustment( 'miDefaultOptions.maxRefractionRays' ) mc.setAttr('miDefaultOptions.maxRefractionRays', 1) mc.editRenderLayerAdjustment( 'miDefaultOptions.maxRayDepth') mc.setAttr('miDefaultOptions.maxRayDepth',1) mc.editRenderLayerGlobals(crl = "defaultRenderLayer") mc.setAttr("defaultRenderLayer.renderable",0) mc.select(cl = True) # mc.checkBoxGrp ('enableColorProfile',e=1,v1=1) # mc.optionMenuGrp('inputColorProfile',e=1,enable=1) # mc.optionMenuGrp('outputColorProfile',e=1,enable=1) # mc.optionMenuGrp('inputColorProfile',e=1 ,sl=1 ) # mc.optionMenuGrp('outputColorProfile',e=1 ,sl=2) # mc.setAttr ("defaultRenderGlobals.inputColorProfile",1) # mc.setAttr ("defaultRenderGlobals.outputColorProfile",2) mc.confirmDialog(t='Message', m = 'Scene setup completed successfully', b='OK', ma = "center")
def configure_layers(self, *args): mate_shaders = self.cwd + '/Scripts/shot_builder/lib/shadow_layer_mtl.ma' scene_references = cmds.ls(references=True) # Reference shader file utils.reference(mate_shaders) # Create render layers if not exist utils.create_render_layers(['FG', 'BG', 'SHD', 'zDepth']) ##### FG START ##### fg_layer_name = 'FG' # Configure vray render elements self.enable_element(fg_layer_name, {'char': True, 'env': False}) # List all object with 'char' tag attribute fg_objects = utils.list_by_tag('char', type='transform') # Move to FG layer cmds.editRenderLayerMembers(fg_layer_name, utils.get_roots(fg_objects), noRecurse=True) ##### FG END ##### ##### BG START ##### bg_layer_name = 'BG' self.enable_element(bg_layer_name, {'char': False, 'env': True}) bg_objects = utils.list_by_tag('env', type='transform') cmds.editRenderLayerMembers(bg_layer_name, utils.get_roots(bg_objects), noRecurse=True) ##### BG END ##### ##### SHD START ##### shadow_layer_name = 'SHD' # Move to foreground and background objects to SHD layer cmds.editRenderLayerMembers(shadow_layer_name, utils.get_roots(fg_objects), noRecurse=True) cmds.editRenderLayerMembers(shadow_layer_name, utils.get_roots(bg_objects), noRecurse=True) # Set currendt layer to SHD cmds.editRenderLayerGlobals(currentRenderLayer=shadow_layer_name) # Assign matte material to foreground objects for node in fg_objects: cmds.select(node) cmds.hyperShade(a='matte') # Assign vray_wrapper material to background objects for node in bg_objects: cmds.select(node) cmds.hyperShade(a='vray_wrapper') # Configure vray render elements self.enable_element(shadow_layer_name, {'char': False, 'env': False}) # Disable all dome lights utils.set_layer_attr('VRayLightDomeShape', 'enabled', False, shadow_layer_name) ##### SHD END ##### ##### zDepth START ##### zdepth_layer_name = 'zDepth' # Move to foreground and background objects to zDepth layer cmds.editRenderLayerMembers(zdepth_layer_name, utils.get_roots(fg_objects), noRecurse=True) cmds.editRenderLayerMembers(zdepth_layer_name, utils.get_roots(bg_objects), noRecurse=True) # Set currendt layer to zDepth cmds.editRenderLayerGlobals(currentRenderLayer='zDepth') # Assign matte shader for FG and BG objects for node in fg_objects + bg_objects: cmds.select(node) cmds.hyperShade(a='matte') # Configure vray render elements self.enable_element(zdepth_layer_name, {'char': False, 'env': False}) # Create zDepth render element zdepth_name = 'vrayRE_Z_depth' if not cmds.objExists(zdepth_name): maya.mel.eval('vrayAddRenderElement zdepthChannel;') cmds.editRenderLayerAdjustment(zdepth_name + ".enabled", layer=zdepth_layer_name) cmds.setAttr(zdepth_name + ".enabled", True) else: print '%s render element already exists' % zdepth_name # Disable all dome lights utils.set_layer_attr('VRayLightDomeShape', 'enabled', False, zdepth_layer_name)