def GetNextTask(task): shot = task.getParent() tasks = shot.getTasks() def sort_types(types): data = {} for t in types: data[t] = t.get('sort') data = sorted(data.items(), key=operator.itemgetter(1)) results = [] for item in data: results.append(item[0]) return results types_sorted = sort_types(ftrack.getTaskTypes()) next_types = None for t in types_sorted: if t.get('typeid') == task.get('typeid'): try: next_types = types_sorted[(types_sorted.index(t) + 1):] except: pass for nt in next_types: for t in tasks: if nt.get('typeid') == t.get('typeid'): return t return None
def __init__(self, parent): QtWidgets.QWidget.__init__(self, parent) self.ui = Ui_WorkflowRelationship() self.ui.setupUi(self) self.ui.versionCombo.addItem('Latest', 'latest') self.ui.versionCombo.addItem('Latest Approved', 'latestapproved') taskTypes = ftrack.getTaskTypes() session = FnAssetAPI.SessionManager.currentSession() host = session.getHost() hostId = host.getIdentifier() selectTaskType = '' if hostId == 'uk.co.foundry.hiero': selectTaskType = 'Compositing' rowCntr = 0 for taskType in sorted(taskTypes, key=lambda x: x.getName().lower()): self.ui.taskCombo.addItem(taskType.getName(), taskType.getEntityRef()) if taskType.getName() == selectTaskType: self.ui.taskCombo.setCurrentIndex(rowCntr) rowCntr += 1
def getTaskTypeByName(self, name): import ftrack for t in ftrack.getTaskTypes(): if t.getName().lower() == name.lower(): return t return None
def GetTaskTypeByName(name): task_types = ftrack.getTaskTypes() result = None for s in task_types: if s.getName().lower() == name.lower(): result = s return result
def get_next_task(task): shot = task.getParent() tasks = shot.getTasks() types_sorted = sort_types(ftrack.getTaskTypes()) next_types = None for t in types_sorted: if t.get('typeid') == task.get('typeid'): try: next_types = types_sorted[(types_sorted.index(t) + 1):] except: pass for nt in next_types: for t in tasks: if nt.get('typeid') == t.get('typeid'): return t return None
def _postBuild(self): '''Perform post build operations.''' self.setWindowTitle('New Entity') # Determine and store current reference. entity = self._bridge.getEntityById(self._currentHref) entityType = self._bridge.getEntityType(self._currentHref) self.currentHref = self.setWhereToCreate(entity) entity = self._bridge.getEntityById(self.currentHref) # Events. self._objectSelector.currentIndexChanged[int].connect( self.objectTypeChanged) self._createButton.clicked.connect(self.accept) self._cancelButton.clicked.connect(self.reject) # Populate selectors and decide which to enable. disableType = None if hasattr(entity, 'createSequence'): self._objectSelector.addItem('Sequence', 'seq') disableType = True if hasattr(entity, 'createShot'): if entityType in ['Project', 'Sequence']: self._objectSelector.addItem('Shot', 'shot') disableType = True if hasattr(entity, 'createTask'): self._objectSelector.addItem('Task', 'task') taskTypes = ftrack.getTaskTypes() for taskType in taskTypes: self._typeSelector.addItem(taskType.getName(), taskType.getEntityRef()) if disableType: self._typeSelector.setEnabled(False) self._typeLabel.setEnabled(False)
# :copyright: Copyright (c) 2015 ftrack import sys import argparse import logging import collections import threading import getpass import ftrack STRUCTURE_NAMES = ['episode', 'sequence', 'shot'] TASK_TYPE_ENUMERATOR_OPTIONS = [{ 'label': task_type.getName(), 'value': task_type.getId() } for task_type in ftrack.getTaskTypes()] TASK_TYPE_LOOKUP = dict((task_type.getId(), task_type.getName()) for task_type in ftrack.getTaskTypes()) def async (fn): '''Run *fn* asynchronously.''' def wrapper(*args, **kwargs): thread = threading.Thread(target=fn, args=args, kwargs=kwargs) thread.start() return wrapper def get_names(base_name, padding, start, end, incremental):
def callback(event): """ This plugin sets the task status from the version status update. """ for entity in event['data'].get('entities', []): # Filter non-assetversions if entity.get('entityType') == 'task' and entity['action'] == 'update': # Find task if it exists task = None try: task = ftrack.Task(id=entity.get('entityId')) except: return # Filter to tasks with "pending changes" status status_check = False if task and task.get('objecttypename') == 'Task': if task.getStatus().get('name').lower() == 'pending changes': status_check = True # check that its an compositing task comp_check = False if status_check: for t in ftrack.getTaskTypes(): if task.get('typeid') == t.get('typeid'): if t.get('name').lower() == 'compositing': comp_check = True scene_asset = None if status_check: try: for a in task.getAssets(assetTypes=['scene']): if task.getName() == a.getName(): scene_asset = a except: pass if scene_asset: version_copy = False try: for version in scene_asset.getVersions(): for c in version.getComponents(): if c.getName().endswith('_work'): # version up scene file path = c.getFilesystemPath() prefix = os.path.basename(path).split('v')[0] extension = os.path.splitext(path)[1] max_version = int(version_get(path, 'v')[1]) for f in os.listdir(os.path.dirname(path)): basename = os.path.basename(f) f_prefix = os.path.basename( basename).split('v')[0] if f_prefix == prefix and basename.endswith( extension): if int(version_get( f, 'v')[1]) > max_version: max_version = int( version_get(f, 'v')[1]) path = os.path.dirname(path) path = os.path.join(path, basename) version_string = 'v' + str(max_version).zfill( 3) ext = os.path.splitext(path)[1] path_dir = os.path.dirname(path) files = [] for f in os.listdir(path_dir): if version_string in f and f.endswith(ext): files.append(os.path.join(path_dir, f)) path = max([f for f in files], key=os.path.getctime) version_number = int(version_get(path, 'v')[1]) if int(version_get( path, 'v')[1]) <= version.getVersion(): version_copy = True if path.split( version_string)[-1] != extension: [new_path, new_version_number] = version_up(path) version_string = 'v' + str( new_version_number).zfill(3) new_name = version_string.join( new_path.split(version_string) [:-1]) + version_string + extension os.rename(new_path, new_name) print 'Renaming to %s' % new_name else: [new_path, new_version_number] = version_up(path) path = task.get('name') for p in task.getParents(): path = p.get('name') + '/' + path msg = "Version from %s" % int( version_number) msg += " to %s on %s" % ( int(new_version_number), path) print msg except: print traceback.format_exc()
def getTaskTypeByName(self, name): for t in ftrack.getTaskTypes(): if t.getName().lower() == name.lower(): return t return None
def renameandcopytoVFX(self, copypath, FTRACK_SERVER='http://192.168.9.200', FTRACK_APIKEY='b445309f-1c5d-40ac-b68b-3fdfb4f3ccb9', LOGNAME='andyguo', PROJECTNAME='Piggy Bank' ): digitregex = re.compile(r'(\d{3,})') os.environ['FTRACK_SERVER'] = FTRACK_SERVER os.environ['FTRACK_APIKEY'] = FTRACK_APIKEY os.environ['LOGNAME'] = LOGNAME import ftrack try: project = ftrack.getProject(PROJECTNAME) print('== get asset types ==') platetypes = [x for x in ftrack.getAssetTypes() if x.get('name') == 'Plate'] # print(platetypes) print('== get task types ==') tasktypes = [x for x in ftrack.getTaskTypes() if x.get('name') == 'Plate'] # print(tasktypes) except: print('this project not available in ftrack') for j in xrange(len(self._cliplist)): # rename every frame as VFX needs item = self._cliplist[j] duration = int(item['endframe']) - int(item['startframe']) + 1 for i in xrange(duration): # diframe = str(item['startframe'] + i).zfill(m.end() - m.start()) oldname = item['metadata'][i]['filepath'] newname = item['sequence'][0] + '_' + item['shot'][0] + '_plate_' + ('%04d' % (1001 + i)) + \ os.path.splitext(oldname)[-1] try: newname = os.path.join(os.path.dirname(oldname), newname) os.rename(oldname, newname) except: print('something error in rename files') # print(oldname, newname) copyfoldername = os.path.dirname(oldname) if self._shouldrenamefolder: oldfolder = os.path .dirname(oldname) newfolder = os.path.join(os.path.dirname(os.path.dirname(oldname)), ('%04d' % (j + 1)) + '_' + item['sequence'][0] + '_' + item['shot'][0]) # print(oldfolder, newfolder) try: os.rename(oldfolder, newfolder) copyfoldername = newfolder except: print('something error in rename folders') # copy to NAS using rsync cmd = 'rsync -avr --progress %s %s' % (copyfoldername.replace(' ', r'\ '), copypath.replace(' ', '\ ')) print(cmd) terminal = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, bufsize=1) with terminal.stdout: for line in iter(terminal.stdout.readline, b''): print line, terminal.wait() # update ftrack Assetbuild and shot try: print('== update shot info ==') shot = ftrack.getShot([PROJECTNAME, item['sequence'][0], item['shot'][0]]) except: print('no such shot %s_%s' % (item['sequence'][0], item['shot'][0])) break try: assetbuildname = '%s_%s_plate' % (item['sequence'][0], item['shot'][0]) previousvesions = [x for x in ftrack.getShot([PROJECTNAME, 'Asset builds']).getShots() if assetbuildname in x.getName()] # print(previousvesions) print('== check previous versions ==') if len(previousvesions) > 0: # print('already got %d verions' % len(previousvesions)) assetbuildname = '%s_%s_plate_%02d' % (item['sequence'][0], item['shot'][0], len(previousvesions)+1) else: assetbuildname = '%s_%s_plate_01' % (item['sequence'][0], item['shot'][0]) print('== create new assetbuild ==') newassetbuild = project.createAssetBuild(assetbuildname) newassetbuild.set('typeid', tasktypes[0].get('typeid')) temp = {} temp['01_sequence'] = item['sequence'][0] temp['02_shot'] = item['shot'][0] temp['05_s3d'] = item['s3d'] temp['06_metadata'] = str(item['metadata']) temp['03_startframe'] = item['startframe'] temp['04_endframe'] = item['endframe'] newassetbuild.setMeta(temp) print('== create new asset ==') asset = newassetbuild.createAsset(name=assetbuildname, assetType=platetypes[0].get('short')) version = asset.createVersion(comment='uploaded by IOFTRACK') for index, frame in enumerate(item['metadata']): # print(item['sequence'][0] + '_' + item['shot'][0] # + '_plate_' + # ('%04d' % (1001 + index)) + # os.path.splitext(oldname)[-1] # ) version.createComponent(name=(item['sequence'][0] + '_' + item['shot'][0] + '_plate_' + ('%04d' % (1001 + index)) + os.path.splitext(oldname)[-1] ), path=(item['sequence'][0] + '_' + item['shot'][0] + '_plate_' + ('%04d' % (1001 + index)) + os.path.splitext(oldname)[-1] )) asset.publish() try: print('== link asset to shot and link reverse ==') # print('asset', newassetbuild) # print('shot', shot) newassetbuild.addSuccessor(shot) newassetbuild.addPredecessor(shot) except: print('something error in link asset to shot') break newassetbuild.createTask('upload by IO', taskType=[x for x in ftrack.getTaskTypes() if x.get('name') == 'Plate'][0], taskStatus=[y for y in ftrack.getTaskStatuses() if y.get('name') == 'Approved'][0]) try: print('== create thumbnails ==') convertcmd = 'convert %s -size 1280x720 %s' % ( os.path.join(os.path.dirname(item['metadata'][0]['filepath']), (item['sequence'][0] + '_' + item['shot'][0] + '_plate_' + ('%04d' % (1001)) + os.path.splitext(oldname)[-1] )).replace(' ', r'\ '), os.path.join(APP_PATH, assetbuildname+'.jpg').replace(' ', r'\ ')) print(convertcmd) convermessage = subprocess.Popen(convertcmd, shell=True, stdout=subprocess.PIPE).communicate()[0] newassetbuild.createThumbnail(os.path.join(APP_PATH, assetbuildname + '.jpg')) except: print('== something error in creating thumbnails') except: print('something error with creating assetbuild') break
def callback(event): """ This plugin sets the task status from the version status update. """ for entity in event['data'].get('entities', []): # Filter non-assetversions if entity.get('entityType') == 'task' and entity['action'] == 'update': # Find task if it exists task = None try: task = ftrack.Task(id=entity.get('entityId')) except: return # Filter to tasks with "pending changes" status status_check = False if task and task.get('objecttypename') == 'Task': if task.getStatus().get('name').lower() == 'pending changes': status_check = True # check that its an compositing task comp_check = False if status_check: for t in ftrack.getTaskTypes(): if task.get('typeid') == t.get('typeid'): if t.get('name').lower() == 'compositing': comp_check = True scene_asset = None if status_check: try: for a in task.getAssets(assetTypes=['scene']): if task.getName() == a.getName(): scene_asset = a except: pass if scene_asset: version_copy = False try: for version in scene_asset.getVersions(): for c in version.getComponents(): if c.getName().endswith('_work'): # version up scene file path = c.getFilesystemPath() prefix = os.path.basename(path).split('v')[0] extension = os.path.splitext(path)[1] max_version = int(version_get(path, 'v')[1]) for f in os.listdir(os.path.dirname(path)): basename = os.path.basename(f) f_prefix = os.path.basename(basename).split('v')[0] if f_prefix == prefix and basename.endswith(extension): if int(version_get(f, 'v')[1]) > max_version: max_version = int(version_get(f, 'v')[1]) path = os.path.dirname(path) path = os.path.join(path, basename) version_string = 'v' + str(max_version).zfill(3) ext = os.path.splitext(path)[1] path_dir = os.path.dirname(path) files = [] for f in os.listdir(path_dir): if version_string in f and f.endswith(ext): files.append(os.path.join(path_dir, f)) path = max([f for f in files], key=os.path.getctime) version_number = int(version_get(path, 'v')[1]) if int(version_get(path, 'v')[1]) <= version.getVersion(): version_copy = True if path.split(version_string)[-1] != extension: [new_path, new_version_number] = version_up(path) version_string = 'v' + str(new_version_number).zfill(3) new_name = version_string.join(new_path.split(version_string)[:-1]) + version_string + extension os.rename(new_path, new_name) print 'Renaming to %s' % new_name else: [new_path, new_version_number] = version_up(path) path = task.get('name') for p in task.getParents(): path = p.get('name') + '/' + path msg = "Version from %s" % int(version_number) msg += " to %s on %s" % (int(new_version_number), path) print msg except: print traceback.format_exc()