def remBg(): global charnames, propnames, setnames charnames, propnames, setnames = [], [], [] charnames, propnames, setnames, miscnames = Utils.listAssets() for each in setnames: refrn = mc.referenceQuery(each, f = True) refNode=mc.referenceQuery(each,rfn=1) if refNode: mc.file(rfn=refNode,rr=1) refObjs=mc.ls('%s*' % refNode) if refObjs:mc.delete(refObjs) else: mc.file(refrn, rr = True) scanScene()
def remBg(): global charnames, propnames, setnames charnames, propnames, setnames = [], [], [] charnames, propnames, setnames, miscnames = Utils.listAssets() for each in setnames: refrn = mc.referenceQuery(each, f=True) refNode = mc.referenceQuery(each, rfn=1) if refNode: mc.file(rfn=refNode, rr=1) refObjs = mc.ls('%s*' % refNode) if refObjs: mc.delete(refObjs) else: mc.file(refrn, rr=True) scanScene()
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 scanScene(): global util, charnames, propnames, setnames, adcharnames, adpropnames, adsetnames, charopt, propopt, setopt util = Utils.utils() #declaring and initialising variables charnames, propnames, setnames, miscnames, charopt, propopt, setopt = [], [], [], [], [], [], [] #find rim/key light folder path from config.xml rmkyfldr = "%s/%s/Location"%(util.path, util.litePath) rmkyfiles = os.listdir(rmkyfldr) ltbgs = [x.replace('', '') for x in rmkyfiles] unrefs = [] #find time folder path from config.xml try: litefldr = "%s/%s/Location/%s"%(util.path, util.litePath,rmkyfiles[0]) except: mc.error("Please set the correct project") return Litefiles = os.listdir(litefldr) ltlites = [x.replace('_rimkey.ma', '') for x in Litefiles] #list all reference nodes in scene and list all unloaded references refs = mc.ls(type = "reference") if refs: for each in refs: if each != "sharedReferenceNode" and each != "_UNKNOWN_REF_NODE_": try: nodes = mc.referenceQuery(each, nodes = True) if not nodes: unrefs.append(each) except: pass else: print '\nNo valid References found.\n' #prompt to load all unloaded references for the scan to proceed, cancel will still show assets but setup will not work if unrefs: nonrefassets = "Following references are unloaded\nLoad all the references?\n\n" + "\n".join(unrefs) + "\n" rslt = mc.confirmDialog(t='Warning', m=nonrefassets, b=['Continue', 'Cancel'], db='Continue', cb='Cancel', ds='Cancel', ma = 'center') if rslt == 'Cancel': pass else: for refs in unrefs: refpath = mc.referenceQuery(refs, f = True) mc.file(refpath, lr = True) #list all assets in the scenes using Utils.listAssets() charnames, propnames, setnames, miscnames = Utils.listAssets() if adcharnames: for each in adcharnames: if not each in charnames: charnames.append(each) if adpropnames: for each in adpropnames: if not each in propnames: propnames.append(each) if adsetnames: for each in adsetnames: if not each in setnames: setnames.append(each) #set the scroll menu placeholder in main UI as the parent menu of the dynamic that we're about to create mc.setParent('scrll') numlayers = mc.intFieldGrp("numgrps", q = True, v1 = True) #column layout for the dynamic menu if mc.columnLayout("assetcol", ex = True): mc.deleteUI("assetcol") mc.columnLayout("assetcol") #listing the characters in the scene mc.separator(h = 5, w = 470, st = 'in') mc.text(l = " CHARACTERS ", fn = "boldLabelFont") mc.separator(h = 5, w = 470, st = 'in') mc.columnLayout(co = ('left', 10)) mc.separator(h = 5, w = 470, st = 'none') #creating the menu for each of the characters in the scene for i in range(len(charnames)): mc.rowLayout(nc = 3, cw3 = (200, 150, 50)) #name of the character mc.text(l = charnames[i]) #select button command com = "mc.select(\"%s\", r = True)"%charnames[i] menulabel = "chmenu%s"%str(i).zfill(2) charopt.append(menulabel) #dropdown list for selecting the render layer group that the character will go into mc.optionMenu(menulabel, label = 'Render Grp : ') for ii in range(numlayers): mc.menuItem( label="ch%s"%str(ii + 1).zfill(2)) mc.menuItem( label="None") #button for selecting the character mc.button(l = "Select", c = com) mc.setParent('..') mc.separator(h = 5, w = 470, st = 'none') mc.rowLayout(nc = 2, cw2 = (100, 300)) #button to add a character that didn't show up in the scan mc.button(l = " Add Character", w = 80, al = "center", c = lambda event:addAsset(0)) mc.text(label = "Select a group and press button to add the character") mc.setParent('..') mc.separator(h = 5, w = 400, st = 'none') mc.setParent('..') #listing the props in the scene mc.separator(h = 5, w = 470, st = 'in') mc.text(l = " PROPS ", fn = "boldLabelFont") mc.separator(h = 5, w = 470, st = 'in') mc.columnLayout(co = ('left', 10)) mc.separator(h = 5, w = 470, st = 'none') #creating the menu for each of the props in the scene for k in range(len(propnames)): mc.rowLayout(nc = 3, cw3 = (200, 150, 50)) #name of the prop mc.text(l = propnames[k]) #select button command com = "mc.select(\"%s\", r = True)"%propnames[k] menulabel = "prmenu%s"%str(k).zfill(2) propopt.append(menulabel) #dropdown list for selecting the render layer group that the prop will go into mc.optionMenu(menulabel, label = 'Render Grp : ') for kk in range(numlayers): mc.menuItem( label="ch%s"%str(kk + 1).zfill(2)) mc.menuItem( label="None") #button for selecting the prop mc.button(l = "Select", c = com) mc.setParent('..') mc.separator(h = 5, w = 470, st = 'none') mc.rowLayout(nc = 2, cw2 = (100, 300)) #button to add a prop that didn't show up in the scan mc.button(l = " Add Prop", w = 80, al = "center", c = lambda event:addAsset(1)) mc.text(label = "Select a group and press button to add the prop") mc.setParent('..') mc.separator(h = 5, w = 470, st = 'none') mc.setParent('..') #listing the bgs in the scene mc.separator(h = 5, w = 470, st = 'in') mc.text(l = " SETS ", fn = "boldLabelFont") mc.separator(h = 5, w = 470, st = 'in') mc.columnLayout(co = ('left', 10)) mc.separator(h = 5, w = 470, st = 'none') #creating the menu for each of the bgs in the scene for l in range(len(setnames)): mc.rowLayout(nc = 3, cw3 = (200, 150, 50)) #name of the bg mc.text(l = setnames[l]) #select button command com = "mc.select(\"%s\", r = True)"%setnames[l] menulabel = "bgmenu%s"%str(l).zfill(2) setopt.append(menulabel) #dropdown list for selecting the render layer group that the bg will go into mc.optionMenu(menulabel, label = 'Render Grp : ') for ll in range(numlayers): mc.menuItem( label="ch%s"%str(ll + 1).zfill(2)) mc.menuItem( label="None") #button for selecting the bg mc.button(l = "Select", c = com) mc.setParent('..') mc.separator(h = 5, w = 470, st = 'none') mc.rowLayout(nc = 2, cw2 = (100, 300)) #button to add a bg that didn't show up in the scan mc.button(l = " Add Set", w = 80, al = "center", c = lambda event:addAsset(2)) mc.text(label = "Select a group and press button to add the set") mc.setParent('..') mc.separator(h = 5, w = 470, st = 'none') mc.setParent('..') mc.separator(h = 5, w = 470, st = 'in') #creating the light options menu mc.setParent('ltopts') if mc.columnLayout("ltopscol", ex = True): mc.deleteUI("ltopscol") mc.columnLayout('ltopscol') mc.rowLayout(nc = 2) mc.rowLayout(nc = 4, cw4 = (39, 39, 39, 39)) mc.checkBox("selchk", label = "all", v = 1, w = 50, cc = lambda event:chkchange()) mc.checkBox("keychk", label = "key", v = 1, w = 39) mc.checkBox("rimchk", label = "rim", v = 1, w = 39) mc.checkBox("colchk", label = "col", v = 1, w = 39) mc.setParent('..') mc.rowLayout(nc = 4, cw4 = (39, 39, 39,39)) mc.checkBox("occchk", label = "occ", v = 1, w = 39) mc.checkBox("rgbachk",label = "rgba",v = 1, w = 43) mc.checkBox("gshchk", label = "gsh", v = 1, w = 39) mc.checkBox("matchk", label = "mat", v = 1, w = 39) mc.setParent('..') mc.setParent('..') mc.separator(h = 15, w = 470, st = 'none') mc.rowLayout(nc = 3, cw3 = (30,250, 150)) mc.text(label='') #checkbox to query whether the references need to be cut mc.checkBox("refchk", label = "Import all references(Cut the references)", v = 0) #checkbox to query whether the cameras need to be exported mc.checkBox("camchk", label = "Export cameras", v = 0) mc.setParent('..') mc.separator(h = 15, w = 470, st = 'none') mc.rowLayout(nc = 4, cw4 = (80,90,110,125)) mc.text(label = "Ambient Light") mc.text(label = " Location") mc.text(label = " Time") mc.text(label = " Render Scene Camera") mc.setParent('..') mc.separator(h = 5, w = 470, st = 'none') mc.rowLayout(nc = 4, cw4 = (80,100,110,145)) #dropdown to query what kind of ambient light to use mc.optionMenu('amblite', label = '') mc.menuItem( label="None") mc.menuItem( label="GI") mc.menuItem( label="ambient") #mc.menuItem( label="GILight") #dropdown to query which rim/key file to use mc.optionMenu('Location', label = '',cc=lambda event:locc()) for each in ltbgs: mc.menuItem( label = each) #dropdown to query which time lights to use mc.optionMenu('Time', label = '') for each in ltlites: mc.menuItem( label = each) #list all cameras in the scene to find out renderable camera cams = mc.ls(type = "camera") rencams = [] epcams = [] #list all cameras that are children of 'CAMERAS' group if mc.objExists('CAMERAS'): epcams = mc.listRelatives('CAMERAS', c = True, ad = True, type = 'camera') #find out the scene camera and set it to renderable if epcams: for each in cams: if each in epcams: rencams.append(each) mc.setAttr((each + ".renderable"), 1) if not rencams: rencams = cams #dropdown to show renderable cameras in the scene. the scene camera will be selected by default mc.optionMenu('camlite', label = '',) renParentCams = [mc.listRelatives(x, p = True)[0] for x in rencams] for each in renParentCams: mc.menuItem( label=each) mc.optionMenu('camlite', e = True, v = (renParentCams[0])) mc.setParent('..') #calculate optimum height of UI window based on the number of assets to be processed numasts = len(charnames) + len(propnames) + len(setnames) if numasts > 12: numasts = 12 scrht = 300 + numasts*25 winht = 590 + numasts*25 #edit the window and scrolllayout heights to be the optimum value mc.window('liteshot', e = True, wh = (483, winht)) mc.scrollLayout('scrll',e = True, h = scrht, w = 450, vis = True)
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 scanScene(): global util, charnames, propnames, setnames, adcharnames, adpropnames, adsetnames, charopt, propopt, setopt util = Utils.utils() #declaring and initialising variables charnames, propnames, setnames, miscnames, charopt, propopt, setopt = [], [], [], [], [], [], [] #find rim/key light folder path from config.xml rmkyfldr = "%s/%s/Location" % (util.path, util.litePath) rmkyfiles = os.listdir(rmkyfldr) ltbgs = [x.replace('', '') for x in rmkyfiles] unrefs = [] #find time folder path from config.xml try: litefldr = "%s/%s/Location/%s" % (util.path, util.litePath, rmkyfiles[0]) except: mc.error("Please set the correct project") return Litefiles = os.listdir(litefldr) ltlites = [x.replace('_rimkey.ma', '') for x in Litefiles] #list all reference nodes in scene and list all unloaded references refs = mc.ls(type="reference") if refs: for each in refs: if each != "sharedReferenceNode" and each != "_UNKNOWN_REF_NODE_": try: nodes = mc.referenceQuery(each, nodes=True) if not nodes: unrefs.append(each) except: pass else: print '\nNo valid References found.\n' #prompt to load all unloaded references for the scan to proceed, cancel will still show assets but setup will not work if unrefs: nonrefassets = "Following references are unloaded\nLoad all the references?\n\n" + "\n".join( unrefs) + "\n" rslt = mc.confirmDialog(t='Warning', m=nonrefassets, b=['Continue', 'Cancel'], db='Continue', cb='Cancel', ds='Cancel', ma='center') if rslt == 'Cancel': pass else: for refs in unrefs: refpath = mc.referenceQuery(refs, f=True) mc.file(refpath, lr=True) #list all assets in the scenes using Utils.listAssets() charnames, propnames, setnames, miscnames = Utils.listAssets() if adcharnames: for each in adcharnames: if not each in charnames: charnames.append(each) if adpropnames: for each in adpropnames: if not each in propnames: propnames.append(each) if adsetnames: for each in adsetnames: if not each in setnames: setnames.append(each) #set the scroll menu placeholder in main UI as the parent menu of the dynamic that we're about to create mc.setParent('scrll') numlayers = mc.intFieldGrp("numgrps", q=True, v1=True) #column layout for the dynamic menu if mc.columnLayout("assetcol", ex=True): mc.deleteUI("assetcol") mc.columnLayout("assetcol") #listing the characters in the scene mc.separator(h=5, w=470, st='in') mc.text(l=" CHARACTERS ", fn="boldLabelFont") mc.separator(h=5, w=470, st='in') mc.columnLayout(co=('left', 10)) mc.separator(h=5, w=470, st='none') #creating the menu for each of the characters in the scene for i in range(len(charnames)): mc.rowLayout(nc=3, cw3=(200, 150, 50)) #name of the character mc.text(l=charnames[i]) #select button command com = "mc.select(\"%s\", r = True)" % charnames[i] menulabel = "chmenu%s" % str(i).zfill(2) charopt.append(menulabel) #dropdown list for selecting the render layer group that the character will go into mc.optionMenu(menulabel, label='Render Grp : ') for ii in range(numlayers): mc.menuItem(label="ch%s" % str(ii + 1).zfill(2)) mc.menuItem(label="None") #button for selecting the character mc.button(l="Select", c=com) mc.setParent('..') mc.separator(h=5, w=470, st='none') mc.rowLayout(nc=2, cw2=(100, 300)) #button to add a character that didn't show up in the scan mc.button(l=" Add Character", w=80, al="center", c=lambda event: addAsset(0)) mc.text(label="Select a group and press button to add the character") mc.setParent('..') mc.separator(h=5, w=400, st='none') mc.setParent('..') #listing the props in the scene mc.separator(h=5, w=470, st='in') mc.text(l=" PROPS ", fn="boldLabelFont") mc.separator(h=5, w=470, st='in') mc.columnLayout(co=('left', 10)) mc.separator(h=5, w=470, st='none') #creating the menu for each of the props in the scene for k in range(len(propnames)): mc.rowLayout(nc=3, cw3=(200, 150, 50)) #name of the prop mc.text(l=propnames[k]) #select button command com = "mc.select(\"%s\", r = True)" % propnames[k] menulabel = "prmenu%s" % str(k).zfill(2) propopt.append(menulabel) #dropdown list for selecting the render layer group that the prop will go into mc.optionMenu(menulabel, label='Render Grp : ') for kk in range(numlayers): mc.menuItem(label="ch%s" % str(kk + 1).zfill(2)) mc.menuItem(label="None") #button for selecting the prop mc.button(l="Select", c=com) mc.setParent('..') mc.separator(h=5, w=470, st='none') mc.rowLayout(nc=2, cw2=(100, 300)) #button to add a prop that didn't show up in the scan mc.button(l=" Add Prop", w=80, al="center", c=lambda event: addAsset(1)) mc.text(label="Select a group and press button to add the prop") mc.setParent('..') mc.separator(h=5, w=470, st='none') mc.setParent('..') #listing the bgs in the scene mc.separator(h=5, w=470, st='in') mc.text(l=" SETS ", fn="boldLabelFont") mc.separator(h=5, w=470, st='in') mc.columnLayout(co=('left', 10)) mc.separator(h=5, w=470, st='none') #creating the menu for each of the bgs in the scene for l in range(len(setnames)): mc.rowLayout(nc=3, cw3=(200, 150, 50)) #name of the bg mc.text(l=setnames[l]) #select button command com = "mc.select(\"%s\", r = True)" % setnames[l] menulabel = "bgmenu%s" % str(l).zfill(2) setopt.append(menulabel) #dropdown list for selecting the render layer group that the bg will go into mc.optionMenu(menulabel, label='Render Grp : ') for ll in range(numlayers): mc.menuItem(label="ch%s" % str(ll + 1).zfill(2)) mc.menuItem(label="None") #button for selecting the bg mc.button(l="Select", c=com) mc.setParent('..') mc.separator(h=5, w=470, st='none') mc.rowLayout(nc=2, cw2=(100, 300)) #button to add a bg that didn't show up in the scan mc.button(l=" Add Set", w=80, al="center", c=lambda event: addAsset(2)) mc.text(label="Select a group and press button to add the set") mc.setParent('..') mc.separator(h=5, w=470, st='none') mc.setParent('..') mc.separator(h=5, w=470, st='in') #creating the light options menu mc.setParent('ltopts') if mc.columnLayout("ltopscol", ex=True): mc.deleteUI("ltopscol") mc.columnLayout('ltopscol') mc.rowLayout(nc=2) mc.rowLayout(nc=4, cw4=(39, 39, 39, 39)) mc.checkBox("selchk", label="all", v=1, w=50, cc=lambda event: chkchange()) mc.checkBox("keychk", label="key", v=1, w=39) mc.checkBox("rimchk", label="rim", v=1, w=39) mc.checkBox("colchk", label="col", v=1, w=39) mc.setParent('..') mc.rowLayout(nc=4, cw4=(39, 39, 39, 39)) mc.checkBox("occchk", label="occ", v=1, w=39) mc.checkBox("rgbachk", label="rgba", v=1, w=43) mc.checkBox("gshchk", label="gsh", v=1, w=39) mc.checkBox("matchk", label="mat", v=1, w=39) mc.setParent('..') mc.setParent('..') mc.separator(h=15, w=470, st='none') mc.rowLayout(nc=3, cw3=(30, 250, 150)) mc.text(label='') #checkbox to query whether the references need to be cut mc.checkBox("refchk", label="Import all references(Cut the references)", v=0) #checkbox to query whether the cameras need to be exported mc.checkBox("camchk", label="Export cameras", v=0) mc.setParent('..') mc.separator(h=15, w=470, st='none') mc.rowLayout(nc=4, cw4=(80, 90, 110, 125)) mc.text(label="Ambient Light") mc.text(label=" Location") mc.text(label=" Time") mc.text(label=" Render Scene Camera") mc.setParent('..') mc.separator(h=5, w=470, st='none') mc.rowLayout(nc=4, cw4=(80, 100, 110, 145)) #dropdown to query what kind of ambient light to use mc.optionMenu('amblite', label='') mc.menuItem(label="None") mc.menuItem(label="GI") mc.menuItem(label="ambient") #mc.menuItem( label="GILight") #dropdown to query which rim/key file to use mc.optionMenu('Location', label='', cc=lambda event: locc()) for each in ltbgs: mc.menuItem(label=each) #dropdown to query which time lights to use mc.optionMenu('Time', label='') for each in ltlites: mc.menuItem(label=each) #list all cameras in the scene to find out renderable camera cams = mc.ls(type="camera") rencams = [] epcams = [] #list all cameras that are children of 'CAMERAS' group if mc.objExists('CAMERAS'): epcams = mc.listRelatives('CAMERAS', c=True, ad=True, type='camera') #find out the scene camera and set it to renderable if epcams: for each in cams: if each in epcams: rencams.append(each) mc.setAttr((each + ".renderable"), 1) if not rencams: rencams = cams #dropdown to show renderable cameras in the scene. the scene camera will be selected by default mc.optionMenu( 'camlite', label='', ) renParentCams = [mc.listRelatives(x, p=True)[0] for x in rencams] for each in renParentCams: mc.menuItem(label=each) mc.optionMenu('camlite', e=True, v=(renParentCams[0])) mc.setParent('..') #calculate optimum height of UI window based on the number of assets to be processed numasts = len(charnames) + len(propnames) + len(setnames) if numasts > 12: numasts = 12 scrht = 300 + numasts * 25 winht = 590 + numasts * 25 #edit the window and scrolllayout heights to be the optimum value mc.window('liteshot', e=True, wh=(483, winht)) mc.scrollLayout('scrll', e=True, h=scrht, w=450, vis=True)