def analizeShotSC(): # Get SHOT DATA from << SCENE >> fileNameFull = pm.sceneName() fileName = fileNameFull.split('/')[-1] codePart = fileNameFull.split('/')[ -4] # get PART NAME from file path (REEL_01, etc) codeSequence = fileNameFull.split('/')[ -3] # get SEQUENCE NUMBER from scene name codeShot = fileNameFull.split('/')[-2].split('SHOT_')[ 1] # get SHOT NUMBER from scene name codeVersion = fileNameFull.split('/')[-1].split('.')[0].split('_')[ -1] # get FILE VERSION from scene name prefix = fileNameFull.split('/')[-1].split('_')[ 0] # get brunch (RIG or GEO) from scene Name if prefix == 'ANM': brunch = 'RIG' elif prefix == 'RND': brunch = 'GEO' else: brunch = 'GEO' dataShotSC = {} dataShotSC['scn_END'] = pm.env.getAnimEndTime() dataShotSC['fileName'] = fileName dataShotSC['prefix'] = prefix dataShotSC['brunch'] = brunch dataShotSC['codePart'] = codePart dataShotSC['codeSequence'] = codeSequence dataShotSC['codeShot'] = codeShot dataShotSC['codeVersion'] = codeVersion dataShotSC['scn_AST'] = pm.getReferences().keys() # Build asset dic by category listAssets = pm.getReferences().values() # Get list of assets FULL PATH print 'listAssets: {}'.format(listAssets) dataShotSC['scn_CHR'] = [] dataShotSC['scn_PRP'] = [] dataShotSC['scn_ENV'] = [] dataShotSC['scn_EDA'] = [] for i in listAssets: dataFileName = fileActs(i) # Get DATA from file PATH assetName = dataFileName['assetName'] assetType = dataFileName['assetType'] if assetType == 'characters': dataShotSC['scn_CHR'].append(assetName) elif assetType == 'props': dataShotSC['scn_PRP'].append(assetName) elif assetType == 'environments': dataShotSC['scn_ENV'].append(assetName) elif assetType == 'eda': dataShotSC['scn_EDA'].append(assetName) print 'dnaCore.analizeShotSC [ dataShotSC ]: {}'.format(dataShotSC) return dataShotSC
def setCamera(self): pm.mel.eval( 'setNamedPanelLayout "Single Perspective View"; updateToolbox();') sceneReferences = pm.getReferences() print sceneReferences camera = '' for item in sceneReferences: if sceneReferences[item].isLoaded(): if referenceCam.lower() in sceneReferences[item].path.lower(): print 'cam loaded already' camera = pm.ls(item + ':*', type='camera')[0] break print referenceCam stageCam = pm.ls(referenceCam + '*', type='camera')[0] print stageCam if stageCam: camera = stageCam if camera == '': if os.path.isfile(referenceCam): pm.createReference(referenceCam, namespace="CAM") camera = pm.ls('CAM:*', type='camera')[0] else: print 'No cam file, creating a default one' cameraList = pm.camera(n='playblastCam') camera = cameraList[1] cameraList[0].setTranslation([0, 10, 60])
def get_dependencies(parent): # TODO: note that a double reference is not currently re-exported, so the nested # reference will not be updated to point at the published file refs = pm.getReferences(parentReference=parent.reference if hasattr(parent, "reference") else None, recursive=False) # only support references with namespaces return [Data(ref=ref) for ref in refs.values() if ref.isUsingNamespaces() and ref.refNode in parent.child_nodes]
def setCamera(self): pm.mel.eval('setNamedPanelLayout "Single Perspective View"; updateToolbox();') sceneReferences = pm.getReferences() print sceneReferences camera = '' for item in sceneReferences : if sceneReferences[item].isLoaded(): if referenceCam.lower() in sceneReferences[item].path.lower(): print 'cam loaded already' camera = pm.ls(item + ':*',type='camera')[0] break print referenceCam stageCam = pm.ls(referenceCam + '*',type='camera')[0] print stageCam if stageCam: camera = stageCam if camera == '': if os.path.isfile(referenceCam): pm.createReference(referenceCam,namespace="CAM") camera = pm.ls('CAM:*',type='camera')[0] else: print 'No cam file, creating a default one' cameraList = pm.camera(n='playblastCam') camera = cameraList[1] cameraList[0].setTranslation([0,10,60])
def assert_reference(namespace, path): model_group = assert_group_chain('animated', '{}_group'.format(namespace), 'model') existing = pm.getReferences() if namespace in existing: ref_node = existing[namespace] ref_path = ref_node.unresolvedPath() if ref_path != path: raise ValueError("Existing {!r} reference {!r} should be {!r}".format( namespace, ref_path, path, )) all_nodes = set(ref_node.nodes()) nodes = [] for node in all_nodes: if pm.nodeType(node) != 'transform': continue parents = pm.listRelatives(node, allParents=True) if not parents or all(p not in all_nodes for p in parents): nodes.append(node) else: before = set(pm.ls(assemblies=True)) ref_node = pm.createReference(path, namespace=namespace, ) if ref_node.namespace != namespace: raise ValueError("Could not create namespace {!r}; got {!r}.".format(namespace, ref_node.namespace)) nodes = list(set(pm.ls(assemblies=True)) - before) for node in nodes: if model_group not in pm.listRelatives(node, allParents=True): pm.parent(node, model_group) return nodes
def analizeVersions(): brunch = analizeShotSC()['brunch'] # Check ASSETS VERSIONS wrongVersions = [] listRefAssets = pm.getReferences().keys( ) # Get CODES of referenced FILES in current scene print 'dnaCore.analizeVersions [ listRefAssets ]: {}'.format(listRefAssets) for i in listRefAssets: # For ecah REFERENCE: Check existing VER, check VER in FTRACK. IF missmatch : ADD to << wrongVersions variable>> pathRef = pm.FileReference(namespace=i) dataFileName = fileActs(pathRef) # Get DATA from file PATH verLoad = dataFileName['fileVresion'] # Version in SCENE assetType = dataFileName['assetType'] assetNameFull = i if assetNameFull: # Check if assetNameFull is NOT empty if not buildAssetDic( i) == None: # Check if ASSET exists in DATABASE if assetType == 'environments': # Fix KEY for environments brunch = 'GEO' pathRefFT = buildAssetDic(i)[brunch] print 'dnaCore.analizeVersions [ pathRefFT ]: {}'.format( pathRefFT) verFT = pathRefFT.split('_')[-1].split('.')[0] if not verLoad == verFT: wrongVersions.append(i) return wrongVersions
def importReferences(*args): try: refs = pm.getReferences() for ref in refs.itervalues(): ref.importContents(removeNamespace=True) return False except IndexError: pass
def analizeShotSC(): # Get SHOT DATA from << SCENE >> fileNameFull = pm.sceneName() fileName = fileNameFull.split('/')[-1] codePart = fileNameFull.split('/')[-4] # get PART NAME from file path (REEL_01, etc) codeSequence = fileNameFull.split('/')[-3] # get SEQUENCE NUMBER from scene name codeShot = fileNameFull.split('/')[-2].split('SHOT_')[1] # get SHOT NUMBER from scene name codeVersion = fileNameFull.split('/')[-1].split('.')[0].split('_')[-1] # get FILE VERSION from scene name prefix = fileNameFull.split('/')[-1].split('_')[0] # get brunch (RIG or GEO) from scene Name if prefix == 'ANM': brunch = 'RIG' elif prefix == 'RND': brunch = 'GEO' else: brunch = 'GEO' dataShotSC = {} dataShotSC['scn_END'] = pm.env.getAnimEndTime() dataShotSC['fileName'] = fileName dataShotSC['prefix'] = prefix dataShotSC['brunch'] = brunch dataShotSC['codePart'] = codePart dataShotSC['codeSequence'] = codeSequence dataShotSC['codeShot'] = codeShot dataShotSC['codeVersion'] = codeVersion dataShotSC['scn_AST'] = pm.getReferences().keys() # Build asset dic by category listAssets = pm.getReferences().values() # Get list of assets FULL PATH print 'listAssets: {}'.format(listAssets) dataShotSC['scn_CHR'] = [] dataShotSC['scn_PRP'] = [] dataShotSC['scn_ENV'] = [] dataShotSC['scn_EDA'] = [] for i in listAssets: dataFileName = fileActs( i ) # Get DATA from file PATH assetName = dataFileName['assetName'] assetType = dataFileName['assetType'] if assetType == 'characters': dataShotSC['scn_CHR'].append(assetName) elif assetType == 'props': dataShotSC['scn_PRP'].append(assetName) elif assetType == 'environments': dataShotSC['scn_ENV'].append(assetName) elif assetType == 'eda': dataShotSC['scn_EDA'].append(assetName) print 'dnaCore.analizeShotSC [ dataShotSC ]: {}' .format(dataShotSC) return dataShotSC
def bs_getReference(): """ @ get all references from the scene and check if it came from valid directory. @ and filter it with asset type like (char, prop, set, vehicle.) Returns: dict. # return dictionary format. mainDict = { 'char':{refNode: {'node':'', 'path':'', 'name':''}, refNode1: {'node':'', 'path':'', 'name':''}}, 'prop':{refNode: {'node':'', 'path':'', 'name':''}, refNode1: {'node':'', 'path':'', 'name':''}}, 'set':{refNode: {'node':'', 'path':'', 'name':''}, refNode1: {'node':'', 'path':'', 'name':''}}, 'vehicle':{refNode: {'node':'', 'path':'', 'name':''}, refNode1: {'node':'', 'path':'', 'name':''}}, } """ allRef = pm.getReferences() # Declare dictionary. mainDict = dict() charDict = dict() propDict = dict() setDict = dict() vehicleDict = dict() for each in allRef.keys(): eachRef = pm.getReferences()[each] projectFolder = bs_pathGenerator.bs_getEnvDetails()['projectFolder'] basePath = '$BSW_PROD_SERVER/' + projectFolder + '/01_pre/' if str(eachRef.unresolvedPath()).startswith(basePath): astDict = dict() astDict['node'] = eachRef.refNode.name() astDict['path'] = str(eachRef.path) astDict['name'] = str(eachRef.path.name) if str(eachRef.path.name).split('_')[1] == 'ch': charDict[eachRef.refNode.name()] = astDict elif str(eachRef.path.name).split('_')[1] == 'pr': propDict[eachRef.refNode.name()] = astDict elif str(eachRef.path.name).split('_')[1] == 'bg': setDict[eachRef.refNode.name()] = astDict elif str(eachRef.path.name).split('_')[1] == 'vh': vehicleDict[eachRef.refNode.name()] = astDict mainDict['char'] = charDict mainDict['prop'] = propDict mainDict['set'] = setDict mainDict['vehicle'] = vehicleDict return mainDict
def bdSetCamera(self, referenceCam): pm.mel.eval( 'setNamedPanelLayout "Single Perspective View"; updateToolbox();') sceneReferences = pm.getReferences() print sceneReferences camera = '' for item in sceneReferences: if sceneReferences[item].isLoaded(): if referenceCam.lower() in sceneReferences[item].path.lower(): print 'cam loaded already' camera = pm.ls(item + ':*', type='camera')[0] break print referenceCam stageCam = pm.ls(referenceCam + '*', type='camera')[0] print stageCam if stageCam: camera = stageCam if camera == '': if os.path.isfile(referenceCam): pm.createReference(referenceCam, namespace="CAM") camera = pm.ls('CAM:*', type='camera')[0] else: print 'No cam file, creating a default one' cameraList = pm.camera(n='playblastCam') camera = cameraList[1] cameraList[0].setTranslation([0, 10, 60]) ''' perspModel = "".join(pm.getPanel(withLabel = 'Persp View')) if perspModel == '': perspModel = "".join(pm.getPanel(withLabel = 'Side View')) print camera, perspModel pm.setFocus(perspModel) ''' perspView = pm.getPanel(wf=1) pm.modelEditor(perspView, e=1, alo=0, activeView=True) pm.modelEditor(perspView, e=1, polymeshes=1, wos=0, grid=0) pm.modelEditor(perspView, e=1, displayAppearance='smoothShaded', displayTextures=1) try: pm.lookThru(perspView, camera) except: print 'Failed to look through playblast camera'
def bdSetCamera(self,referenceCam): pm.mel.eval('setNamedPanelLayout "Single Perspective View"; updateToolbox();') sceneReferences = pm.getReferences() print sceneReferences camera = '' for item in sceneReferences : if sceneReferences[item].isLoaded(): if referenceCam.lower() in sceneReferences[item].path.lower(): print 'cam loaded already' camera = pm.ls(item + ':*',type='camera')[0] break print referenceCam stageCam = pm.ls(referenceCam + '*',type='camera')[0] print stageCam if stageCam: camera = stageCam if camera == '': if os.path.isfile(referenceCam): pm.createReference(referenceCam,namespace="CAM") camera = pm.ls('CAM:*',type='camera')[0] else: print 'No cam file, creating a default one' cameraList = pm.camera(n='playblastCam') camera = cameraList[1] cameraList[0].setTranslation([0,10,60]) ''' perspModel = "".join(pm.getPanel(withLabel = 'Persp View')) if perspModel == '': perspModel = "".join(pm.getPanel(withLabel = 'Side View')) print camera, perspModel pm.setFocus(perspModel) ''' perspView = pm.getPanel(wf=1) pm.modelEditor(perspView,e=1,alo=0,activeView = True) pm.modelEditor(perspView,e=1,polymeshes=1,wos=0,grid=0) pm.modelEditor(perspView,e=1,displayAppearance='smoothShaded',displayTextures=1) try: pm.lookThru(perspView,camera) except: print 'Failed to look through playblast camera'
def getSceneReferences(self): sceneReferences = pm.getReferences() loadedReferences = [] #print '___________SCENE REFERENCES _____________ %s'%sceneReferences for item in sceneReferences: #print '___________REFERENCE _____________ %s'%sceneReferences[item] #print '___________REFERENCE LOADED _____________ %s'%sceneReferences[item].isLoaded() #print '___________REFERENCE path _____________ %s'%sceneReferences[item].path if sceneReferences[item].isLoaded() and self.toExport( sceneReferences[item]): loadedReferences.append([ sceneReferences[item].isLoaded(), item, os.path.abspath(sceneReferences[item].path) ]) #print '___________LOADED REFERENCES _____________ %s'%loadedReferences return loadedReferences
def bdPopulateReferences(self): self.sceneReferences = pm.getReferences() self.loadedReferences = [] for item in self.sceneReferences: if self.sceneReferences[item].isLoaded(): self.loadedReferences.append([ self.sceneReferences[item].isLoaded(), item, self.sceneReferences[item].path ]) self.referencesTableWidget.setColumnCount(3) self.referencesTableWidget.setRowCount(len(self.loadedReferences)) for i in range(len(self.loadedReferences)): for j in range(3): print self.loadedReferences[i][j] item = QtGui.QTableWidgetItem(str(self.loadedReferences[i][j])) item.setFlags(~QtCore.Qt.ItemIsEditable) self.referencesTableWidget.setItem(i, j, item)
def analizeVersions(): brunch = analizeShotSC()['brunch'] # Check ASSETS VERSIONS wrongVersions = [] listRefAssets = pm.getReferences().keys() # Get CODES of referenced FILES in current scene print 'dnaCore.analizeVersions [ listRefAssets ]: {}'.format(listRefAssets) for i in listRefAssets: # For ecah REFERENCE: Check existing VER, check VER in FTRACK. IF missmatch : ADD to << wrongVersions variable>> pathRef = pm.FileReference(namespace = i) dataFileName = fileActs(pathRef) # Get DATA from file PATH verLoad = dataFileName['fileVresion'] # Version in SCENE assetType = dataFileName['assetType'] assetNameFull = i if assetNameFull: # Check if assetNameFull is NOT empty if not buildAssetDic(i) == None: # Check if ASSET exists in DATABASE if assetType == 'environments': # Fix KEY for environments brunch = 'GEO' pathRefFT = buildAssetDic(i)[brunch] print 'dnaCore.analizeVersions [ pathRefFT ]: {}'.format(pathRefFT) verFT = pathRefFT.split('_')[-1].split('.')[0] if not verLoad == verFT: wrongVersions.append(i) return wrongVersions
def get_references(): # Determine references currently in scene references = pm.getReferences() print "Referenced files include: %s" % (references)
def sceneRefCheck(silent=False): """ Compare the current scene references versions with metadata and update as needed :param silent: boolean :return: """ uptodate = True print 'init sceneChecking...' currentProject = database.getCurrentProject() projName = pm.fileInfo.get('projectName') if currentProject != projName: print 'ERROR sceneRefCheck: This file is from a project different from the current project' return item = Item(fromScene=True) # get current scene metadata # compare references and metadata and create lists of references to add, delete, update and replace refOnSceneList = pm.getReferences() toDelete = [x for x in refOnSceneList if x not in item.components] toAdd = [x for x in item.components if x not in refOnSceneList and x != 'cam'] toReplace = [x for x in item.components if item.components[x]['task'] != item.components[x]['proxyMode']] refToCheckUpdate = [x for x in refOnSceneList if x not in toDelete and x not in toReplace] toUpdate = {} # create the list of references to update depending on the assemble mode for ns in refToCheckUpdate: if item.components[ns]['assembleMode'] == 'camera': continue if item.components[ns]['assembleMode'] == 'reference': component = ReferenceComponent(ns, item.components[ns], parent=item) toUpdate[ns] = component.updateVersion(refOnSceneList[ns]) if item.components[ns]['assembleMode'] == 'xlo': component = XloComponent(ns, item.components[ns], parent=item) toUpdate[ns] = component.updateVersion(refOnSceneList[ns]) if item.components[ns]['assembleMode'] == 'cache': cache = CacheComponent(ns, item.components[ns], parent=item) toUpdate[ns] = cache.updateVersion(refOnSceneList[ns]) # If not in silent mode, show dialogs to the user choose which references should be processed if not silent: if toDelete: uptodate = False toDelete = pm.layoutDialog(ui=lambda: refCheckPrompt(toDelete, 'delete')).split(',') if toAdd: uptodate = False toAdd = pm.layoutDialog(ui=lambda: refCheckPrompt(toAdd, 'add')).split(',') if toReplace: uptodate = False toReplace = pm.layoutDialog(ui=lambda: refCheckPrompt(toReplace, 'replace')).split(',') upDateList = [x for x, y in toUpdate.iteritems() if y ] if upDateList: uptodate = False upDateList = pm.layoutDialog(ui=lambda: refCheckPrompt(upDateList, 'update')).split(',') toUpdate = {x: y for x, y in toUpdate.iteritems() if x in upDateList} else: toUpdate = {} if uptodate: pm.confirmDialog(title='Scene Check', ma='center', message='Versions ok!', button=['OK'], defaultButton='OK', dismissString='OK') # Do the processing # delete print 'toDelete:%s' % toDelete for ns in toDelete: refOnSceneList[ns].remove() # add print 'toAdd:%s' % toAdd for ns in toAdd: if item.components[ns]['assembleMode'] == 'camera': continue print ns if item.components[ns]['assembleMode'] == 'reference': component = ReferenceComponent(ns, item.components[ns], parent=item) component.addToScene() elif item.components[ns]['assembleMode'] == 'xlo': component = XloComponent(ns, item.components[ns], parent=item) component.addToScene() cache = CacheComponent(ns, item.components[ns], parent=item) cache.importCache() elif item.components[ns]['assembleMode'] == 'cache': cache = CacheComponent(ns, item.components[ns], parent=item) cache.addToScene() #update versions for ns, versions in toUpdate.iteritems(): if item.components[ns]['assembleMode'] == 'camera': continue if item.components[ns]['assembleMode'] == 'reference': component = ReferenceComponent(ns, item.components[ns], parent=item) componentPath = component.getPublishPath() refOnSceneList[ns].replaceWith(componentPath) if item.components[ns]['assembleMode'] == 'xlo': if 'ver' in versions: component = XloComponent(ns, item.components[ns], parent=item) componentPath = component.getPublishPath() refOnSceneList[ns].replaceWith(componentPath) if 'cacheVer' in versions: #todo check if need to delete old cache node cache = CacheComponent(ns, item.components[ns], parent=item) cache.importCache() if item.components[ns]['assembleMode'] == 'cache': component = CacheComponent(ns, item.components[ns], parent=item) componentPath = component.getPublishPath() refOnSceneList[ns].replaceWith(componentPath) # Replace for ns in toReplace: if item.components[ns]['assembleMode'] == 'reference': print item.components[ns]['task'], item.components[ns]['proxyMode'] item.components[ns]['task'] = item.components[ns]['proxyMode'] print item.components[ns]['task'], item.components[ns]['proxyMode'] component = ReferenceComponent(ns, item.components[ns], parent=item) print component.getPublishPath() # todo check if existe uma versao refOnSceneList[ns].replaceWith(component.getPublishPath()) item.putDataToDB() print 'done sceneChecking!'
def populateReferences(self, inScene): if inScene: self.sceneReferences = pm.getReferences() self.loadedReferences = [] for item in self.sceneReferences: if self.sceneReferences[item].isLoaded(): self.loadedReferences.append([ self.sceneReferences[item].isLoaded(), item, self.sceneReferences[item].path ]) self.referencesTable.setRowCount(len(self.loadedReferences)) for i in range(len(self.loadedReferences)): for j in range(3): #print self.loadedReferences[i][j] item = QtGui.QTableWidgetItem( str(self.loadedReferences[i][j])) item.setFlags(~QtCore.Qt.ItemIsEditable) self.referencesTable.setItem(i, j, item) else: rigSuffix = pm.optionVar.get('rigString', '') cacheSuffix = pm.optionVar.get('cacheString', '') rigsFolderString = pm.optionVar.get('rigsFolderString', '') shadeFolderString = pm.optionVar.get('shadeFolderString', '') if os.path.isdir(rigsFolderString): rigsPath = os.path.abspath(rigsFolderString) for root, dirnames, filenames in os.walk(rigsPath): for filename in fnmatch.filter(filenames, '*' + rigSuffix + '*.*'): if filename.endswith('.ma') or filename.endswith( '.mb'): shadeFile = self.getShadeFile(filename) rigFile = os.path.join(root, filename) if shadeFile is not 'None': self.rigShadePairs[rigFile] = shadeFile pairsLen = len(self.rigShadePairs) if pairsLen: self.referencesTable.setRowCount(pairsLen) i = 0 for rig, shade in self.rigShadePairs.iteritems(): if shade is not 'None': item = QtGui.QTableWidgetItem(rig) item.setFlags(~QtCore.Qt.ItemIsEditable) self.referencesTable.setItem(i, 0, item) item = QtGui.QTableWidgetItem(shade) item.setFlags(~QtCore.Qt.ItemIsEditable) self.referencesTable.setItem(i, 1, item) item = QtGui.QTableWidgetItem('No') item.setFlags(~QtCore.Qt.ItemIsEditable) item.setBackground(QtGui.QColor(180, 0, 0)) self.referencesTable.setItem(i, 2, item) item.setTextAlignment(QtCore.Qt.AlignCenter) self.referencesTable.setItem(i, 2, item) i += 1 self.addUserPair() self.referencesTable.resizeColumnsToContents() self.referencesTable.setSortingEnabled(1)