def checkVersions(): """ Update the current file metadata with component versions on the database :return: """ item = Item(fromScene=True) for ns, componentMData in item.components.iteritems(): if ns == 'cam': # todo tratar versoes da camera continue if componentMData['assembleMode'] == 'reference': refComponent = ReferenceComponent(ns, componentMData, parent=item) refComponent.checkDBForNewVersion() elif componentMData['assembleMode'] == 'xlo': xloComponent = XloComponent(ns, componentMData, parent=item) xloComponent.checkDBForNewVersion() xloComponent.checkDBForNewCacheVersion() elif componentMData['assembleMode'] == 'cache': cacheComponent = CacheComponent(ns, componentMData, parent=item) cacheComponent.checkDBForNewVersion() item.putDataToDB()
def saveAs(type, task, code, force=True): pm.fileInfo['type'] = 'type' pm.fileInfo['task'] = 'task' pm.fileInfo['code'] = 'code' item = Item(task=task, code=code, itemType=type) item.saveAs()
def open(type, task, code, force=False): if not force: resp = checkModified() if resp == 'Save': pm.saveFile() elif resp == 'Cancel': return item = Item(task=task, code=code, itemType=type) item.open()
def cacheCamera(task, code): shot = Item(task=task, code=code, itemType='shot') if 'cam' not in shot.caches: shot.caches['cam'] = { 'code': '0000', 'ver': 1, 'updateMode': 'last', 'task': 'rig', 'assembleMode': 'camera', 'type': 'asset', 'cacheVer': 0, 'name': '' } camera = CameraComponent('cam', shot.caches['cam'], parent=shot) camera.wrapData() if not camera.cameraTransform: pm.confirmDialog(title='No Camera', ma='center', icon='information', message='No camera to cache', button=['OK'], defaultButton='OK', dismissString='ok') return shot.caches['cam']['cacheVer'] += 1 cacheFullPath = camera.getCachePublishPath(make=True) jobCam = ' -root ' + camera.cameraTransform.name() jobFile = " -file " + cacheFullPath ini = str(int(pm.playbackOptions(q=True, min=True))) fim = str(int(pm.playbackOptions(q=True, max=True))) jobFrameRange = ' -frameRange ' + ini + ' ' + fim # set parameters for alembic cache jobAttr = ' -attr translateX -attr translateY -attr translateZ -attr rotateX ' \ '-attr rotateY -attr rotateZ -attr scaleX -attr scaleY -attr scaleZ -attr visibility' jobOptions = " -worldSpace -writeVisibility" # build cache arguments jobArg = jobFrameRange + jobOptions + jobAttr + jobCam + jobFile # do caching pm.AbcExport(j=jobArg) shot.putDataToDB()
def open(type, task, code, force=False): if not force: resp = checkModified() print resp if resp == 'Save': print pm.saveFile() elif resp == 'Cancel': print 'canceling' return print 'opening' item = Item(task=task, code=code, itemType=type) item.open()
def getItem(self): """ Return the Item this component points to :return: api.Item """ return Item(task=self.task, code=self.code, itemType=self.type)
def publishFile(self, *args): # get database info on item item = Item(task=self.task, code=self.code, itemType=self.type) item.proxyMode = self.proxyMode item.publishAs() version.takeSnapShot(item.getDataDict()) self.closeWin() logger.debug('publish ver %s, at %s' % (item.publishVer, item.getPublishPath())) resp = pm.confirmDialog( title='Warning', ma='center', message='PUBLISH: %s %s \n Reopen working task?' % (item.name, item.task), button=['Ok', 'No'], defaultButton='Ok', dismissString='No') if resp == 'Ok': version.open(type=item.type, task=item.task, code=item.code, force=True) else: pm.newFile(f=True, new=True)
def getItem(self): if self.ns != 'cam': return Item(task='xlo', code=self.code, itemType=self.type) else: return Item(task='rig', code=self.code, itemType=self.type)
def ingestGroups(pathSrc, pathTgt): groupPath = r'wolftv\asset\group' proxyModelPath = r'modeling\proxy_model\desc' groupsFullPath = os.path.join(pathSrc, groupPath) logger.debug('groupFullPath: %s' % groupsFullPath) fileList = pm.getFileList(folder=groupsFullPath) progressWin = ProgressWindowWidget(title='groups', maxValue=len(fileList)) for group in fileList: logger.info('importing %s to pipeLine' % group) progressWin.progressUpdate(1) fileName = group versionPath = os.path.join(groupsFullPath, fileName, proxyModelPath) versionsAvailable = pm.getFileList(folder=versionPath) maxVer = 0 for ver in versionsAvailable: verNum = int(ver[1:]) maxVer = max(maxVer, verNum) version = 'v%03d' % maxVer groupFullPath = os.path.join(versionPath, version) groupFile = pm.getFileList(folder=groupFullPath)[0] groupFullPath = os.path.join(groupFullPath, groupFile) ingestionDict = { 'name': fileName, 'version': maxVer, 'sourcePath': groupFullPath, 'assetType': 'group', 'task': 'proxy', 'setAssemble': os.path.split(pathSrc)[-1] } database.incrementNextCode('asset', fromBegining=True) itemMData = database.createItem( itemType='asset', name=fileName, path=pathTgt, workflow='group', customData={'ingestData': ingestionDict}) itemProxy = Item(task='proxy', code=itemMData['proxy']['code']) itemModel = Item(task='model', code=itemMData['model']['code']) descDict = readDescription(groupFullPath, 1, maxDepth=0, searchInGroupAsset=True) for component in descDict: logger.debug('add %s to %s' % (component['name'], fileName)) itemList = database.searchName(component['name']) if 0 < len(itemList) > 1: proxyComponentMData = database.addSource( item=itemProxy.getDataDict(), ns='ref', componentCode=itemList[0]['code'], componentTask='proxy', assembleMode='reference', update=True, proxyMode='proxy', xform=component['xform'], onSceneParent='') modelComponentMData = database.addSource( item=itemModel.getDataDict(), ns='ref', componentCode=itemList[0]['code'], componentTask='proxy', assembleMode='reference', update=True, proxyMode='model', xform=component['xform'], onSceneParent='') progressWin.closeWindow()
def ingestPieces(pathSrc, pathTgt): setPiecesPath = r'wolftv\asset\set_piece' proxyModelPath = r'modeling\proxy_model\source' setPiecesFullPath = os.path.join(pathSrc, setPiecesPath) fileList = pm.getFileList(folder=setPiecesFullPath) progressWin = ProgressWindowWidget(title='set pieces', maxValue=len(fileList)) for piece in fileList: logger.info('importing %s to pipeLine' % piece) progressWin.progressUpdate(1) fileName = piece versionPath = os.path.join(setPiecesFullPath, fileName, proxyModelPath) versionsAvailable = pm.getFileList(folder=versionPath) maxVer = 0 for ver in versionsAvailable: verNum = int(ver[1:]) maxVer = max(maxVer, verNum) version = 'v%03d' % maxVer pieceFullPath = os.path.join(versionPath, version) pieceFile = pm.getFileList(folder=pieceFullPath)[0] pieceFullPath = os.path.join(pieceFullPath, pieceFile) ingestionDict = { 'name': fileName, 'version': maxVer, 'sourcePath': pieceFullPath, 'assetType': 'set_piece', 'task': 'proxy', 'setAssemble': os.path.split(pathSrc)[-1] } database.incrementNextCode('asset', fromBegining=True) itemMData = database.createItem( itemType='asset', name=fileName, path=pathTgt, workflow='static', customData={'ingestData': ingestionDict}) item = Item(task='proxy', code=itemMData['proxy']['code']) item.status = 'created' item.putDataToDB() workPath = item.getWorkPath(make=True) shutil.copyfile(pieceFullPath, workPath) prj = database.getCurrentProject() insertFileInfo(workPath, projectName=prj, task=item.task, code=item.code, type=item.type) # done copy to publish folder item.publishVer += 1 publishPath = item.getPublishPath(make=True) shutil.copyfile(workPath, publishPath) item.putDataToDB() logger.info('%s imported as %s and published' % (piece, item.task + item.code + item.name)) progressWin.closeWindow()
def getItem(self): return Item(task=self.task, code=self.code, itemType=self.type)
def build(itemType, task, code): parcial = False empty = True item = Item(task=task, code=code, itemType=itemType) if not item.source: itemList = item.components else: itemList = item.source pm.newFile(f=True, new=True) newComponentsDict = {} if item.type == 'shot': print 'creating camera...' cameraItem = Item(task='rig', code='0000', itemType='asset') print cameraItem.noData if cameraItem.noData: pm.confirmDialog(title='No base camera', ma='center', message='Please make an asset code:0000 as base camera', button=['OK'], defaultButton='OK', dismissString='OK') return cameraMData = {'code': '0000', 'ver': cameraItem.publishVer, 'updateMode': 'last', 'task': 'rig', 'assembleMode': 'camera','proxyMode':'rig', 'type': 'asset'} camera = CameraComponent('cam', cameraMData, parent=item) camera.wrapData() if not camera.cameraTransform: camera.addToScene() newComponentsDict['cam'] = camera.getDataDict() for ns, sourceMData in itemList.iteritems(): source = SceneSource(ns, sourceMData, parent=item) sourceItem = source.getItem() if sourceItem.publishVer == 0: print 'Component %s not yet published!!' % (ns + ':' + source.task + source.code) parcial = True continue empty = False if source.assembleMode == 'import': source.importToScene() elif source.assembleMode == 'reference': newComponentsDict[ns] = source.addReferenceToScene() elif source.assembleMode == 'copy': newComponentsDict = source.copyToScene() elif source.assembleMode == 'cache': newComponentsDict = source.addCacheToScene() elif source.assembleMode == 'xlo': newComponentsDict = source.addXloToScene() item.components = newComponentsDict # update infos on scene and database if not empty or not item.components: pm.fileInfo['projectName'] = database.getCurrentProject() pm.fileInfo['task'] = item.task pm.fileInfo['code'] = item.code pm.fileInfo['type'] = item.type if item.type == 'shot': pm.playbackOptions(ast=item.frameRange[0], aet=item.frameRange[1]) pm.currentUnit(time='film') item.workVer = 1 item.status = 'created' item.putDataToDB() sceneDirPath = item.getPath()[0] sceneFullPath = item.getWorkPath() if not os.path.exists(sceneDirPath): os.makedirs(sceneDirPath) pm.saveAs(sceneFullPath) if parcial: item.status = 'partial' pm.confirmDialog(title='Warning', ma='center', message='WARNING build: Some components have no publish to complete build this file!', button=['OK'], defaultButton='OK', dismissString='OK') item.putDataToDB() else: pm.confirmDialog(title='Warning', ma='center', message='%s assembled sucessfully!' % item.filename, button=['OK'], defaultButton='OK', dismissString='OK') else: pm.confirmDialog(title='Warning', ma='center', message='ERROR build: No component published to build this file', button=['OK'], defaultButton='OK', dismissString='OK')
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 build(itemType=None, task=None, code=None, silent=False): logger.debug('initiate Scene Building %s %s %s' % (task, code, itemType)) parcial = False empty = True item = Item(task=task, code=code, itemType=itemType) if not item.source: logger.debug('No source found. Using components') logger.debug('components %s' % item.components) itemUnOrdered = item.components else: logger.debug('Using source') itemUnOrdered = item.source pm.newFile(f=True, new=True) newComponentsDict = {} itemDict = OrderedDict() parentList = [''] count = 0 while len(itemUnOrdered) != len(itemDict): count += 1 level = [[key, x['code']] for key, x in itemUnOrdered.iteritems() if x['onSceneParent'] in parentList] parentList = [x[1] for x in level] for x in level: itemDict[x[0]] = itemUnOrdered[x[0]] if count > 100: break logger.debug(itemDict) if item.type == 'shot': logger.debug('creating camera...') cameraItem = Item(task='rig', code='0000', itemType='asset') if cameraItem.noData: pm.confirmDialog(title='No base camera', ma='center', message='Please make an asset code:0000 as base camera', button=['OK'], defaultButton='OK', dismissString='OK') return cameraMData = {'code': '0000', 'ver': cameraItem.publishVer, 'updateMode': 'last', 'task': 'rig', 'assembleMode': 'camera', 'proxyMode': 'rig', 'onSceneParent': None, 'type': 'asset', 'xform': {}} camera = CameraComponent('cam', cameraMData, parent=item) camera.wrapData() if not camera.cameraTransform: camera.addToScene() newComponentsDict['cam'] = camera.getDataDict() empty = False for ns, sourceMData in itemDict.iteritems(): source = SceneSource(ns, sourceMData, parent=item) if source.assembleMode == 'createGroup': source.createGroup() empty = False for ns, sourceMData in itemDict.iteritems(): source = SceneSource(ns, sourceMData, parent=item) sourceItem = source.getItem() if sourceItem.publishVer == 0: logger.warn('Component %s not yet published!!' % (ns + ':' + source.task + source.code)) parcial = True newComponentsDict[ns] = sourceMData continue empty = False if source.assembleMode == 'import': source.importToScene() elif source.assembleMode == 'reference': newComponentsDict[ns] = source.addReferenceToScene() elif source.assembleMode == 'copy': newComponentsDict = source.copyToScene() elif source.assembleMode == 'cache': newComponentsDict = source.addCacheToScene() elif source.assembleMode == 'xlo': newComponentsDict = source.addXloToScene() item.components = newComponentsDict # update infos on scene and database if not empty or not item.components: pm.fileInfo['projectName'] = database.getCurrentProject() pm.fileInfo['task'] = item.task pm.fileInfo['code'] = item.code pm.fileInfo['type'] = item.type if item.type == 'shot': pm.playbackOptions(ast=item.frameRange[0], aet=item.frameRange[1]) pm.currentUnit(time='film') item.workVer = 1 item.status = 'created' item.putDataToDB() sceneDirPath = item.getPath()[0] sceneFullPath = item.getWorkPath() if not os.path.exists(sceneDirPath): os.makedirs(sceneDirPath) pm.saveAs(sceneFullPath) if parcial: # todo make parcial rebuild item.status = 'partial' if not silent: pm.confirmDialog(title='Warning', ma='center', message='WARNING build: Some components have no publish to complete build this file!', button=['OK'], defaultButton='OK', dismissString='OK') else: logger.warn ('Some components have no publish to complete build this file!' '') item.putDataToDB() else: if not silent: pm.confirmDialog(title='Warning', ma='center', message='%s assembled sucessfully!' % item.filename, button=['OK'], defaultButton='OK', dismissString='OK') else: logger.info('%s assembled sucessfully!' % item.filename) else: if not silent: pm.confirmDialog(title='Warning', ma='center', message='ERROR build: No component published to build this file', button=['OK'], defaultButton='OK', dismissString='OK') else: logger.error('No component published to build this file')