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 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 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)