Alican

Members
  • Content Count

    6
  • Joined

  • Last visited

  1. Just wondering if there are any updates on this issue. I would like to start upgrading our internal scripts to Python3 as we are only few months away from 2020. Downloaded the latest version of python (Python3.8), and installed ftrack-python-api using pip. And just like Reynaldos results, it installed fine but having difficulty importing ftrack_api. Results after import ftrack_api: Traceback (most recent call last): File "L:\HAL\Alican\Logger\import_psutil.py", line 3, in <module> import ftrack_api File "C:\Program Files\Python38\lib\site-packages\ftrack_api\__init__.py", line 5, in <module> from .session import Session File "C:\Program Files\Python38\lib\site-packages\ftrack_api\session.py", line 27, in <module> import ftrack_api.exception File "C:\Program Files\Python38\lib\site-packages\ftrack_api\exception.py", line 7, in <module> import ftrack_api.entity.base File "C:\Program Files\Python38\lib\site-packages\ftrack_api\entity\base.py", line 11, in <module> import ftrack_api.attribute File "C:\Program Files\Python38\lib\site-packages\ftrack_api\attribute.py", line 13, in <module> import ftrack_api.collection File "C:\Program Files\Python38\lib\site-packages\ftrack_api\collection.py", line 15, in <module> import ftrack_api.cache File "C:\Program Files\Python38\lib\site-packages\ftrack_api\cache.py", line 24, in <module> import anydbm ModuleNotFoundError: No module named 'anydbm' Thank you in advance! Ali
  2. Hello everybody! This action populates some custom attributes within a Task that is nested under selected item. These attributes are paths to working directories and render outputs.. I have other actions that rely on these custom paths to do other things such as opening a shot with quicktime / launching the shot folder in explorer /etc.. Everything works as it should.... but I am concerned about the efficiency and speed of my code as populating each task takes about a second... and of course, the more tasks nested under my selection, the longer this process takes. Ideally... I would like to run this action at Project or at least Sequence level and let it update the custom attributes for all tasks nested under it. EpisodicS2 └-- Episode1 └-- Seq001 └-- Shot1 └-- Task1 └-- Task2 └-- Task..10 Am I doing everything right? Are there major deficiencies in my code? Thank you for all the help! Ali import logging import ftrack_api import os import re import ftrack import getpass import time os.environ['FTRACK_SERVER'] = ### os.environ['FTRACK_API_KEY'] = ### #this script will populate parameters of each task and shot nested under selected item with direct paths to file locations. ### prerequisites: #Task should have the following attributes : path, out_path, base_path #Shot should have the following attributes : plate_path #Project should have the following attributes : Project_Path #<----naming will need to be conformed ### class UpdatePaths(object): '''Custom action.''' label = 'Update Paths' identifier = 'update.task.paths' description = 'This updates the path parameter of all tasks nested under selected' icon = 'https://d30y9cdsu7xlg0.cloudfront.net/png/1406969-200.png' def __init__(self, session): '''Initialise action.''' super(UpdatePaths, self).__init__() self.session = session self.logger = logging.getLogger( __name__ + '.' + self.__class__.__name__ ) def register(self): '''Register action.''' try: ftrack.EVENT_HUB.subscribe( 'topic=ftrack.action.discover and source.user.username={0}'.format( getpass.getuser() ), self.discover ) ftrack.EVENT_HUB.subscribe( 'topic=ftrack.action.launch and source.user.username={0} ' 'and data.actionIdentifier={1}'.format( getpass.getuser(), self.identifier ), self.launch ) except: self.session.event_hub.subscribe( 'topic=ftrack.action.discover', self.discover ) self.session.event_hub.subscribe( 'topic=ftrack.action.launch and data.actionIdentifier={0}'.format( self.identifier), self.launch ) def discover(self, event): '''Return action config if triggered on a single asset version.''' data = event['data'] # If selection contains more than one item return early since # this action can only handle a single version. selection = data.get('selection', []) self.logger.info('Got selection: {0}'.format(selection)) #if len(selection) != 1 or selection[0]['entityType'] != 'assetversion': # return return { 'items': [{ 'label': self.label, 'description': self.description, 'actionIdentifier': self.identifier, 'icon': self.icon }] } def launch(self, event): start_time = time.time() data = event['data'] selection = data.get('selection', []) entityTypes = ['Project', 'Episode', 'Sequence', 'Shot', 'Task'] session = ftrack_api.Session() for entity in selection: num = 0 et = entityTypes[num] item = session.query('select name from {0} where id is {1}'.format(et, entity['entityId'])).first() while item == None: num += 1 et = entityTypes[num] item = session.query('select name from {0} where id is {1}'.format(et, entity['entityId'])).first() prj_item_selected = False #If the current selected item is a project, first process it byitself. if item['parent'] == None: project = item prj_item_selected = True project_base = item['custom_attributes']['Project_Path']+item['full_name']+'/' if item['custom_attributes']['base_path']!= project_base: item['custom_attributes']['base_path'] = project_base #now look for the selected items descendants items = item['descendants'][:] #if the selected item is not a project, then we will also need to add taht to the list we will iterate through. if not prj_item_selected: items += [item] project = session.get('Project', item['project_id']) print 'Total nested items:',len(items) for i in items: link_list = i['link'][1:] episode = '' #search for an episode item in the links for l in link_list: link_item = session.get(l['type'], l['id']) if link_item['object_type']['name'] == 'Episode': episode = link_item['name'] project_path = project['custom_attributes']['Project_Path'] project_name = project['full_name'] base_path = project_path+project_name+'/'+episode+'/' base_path = base_path.replace('//','/') if i['custom_attributes']['base_path'] != base_path: i['custom_attributes']['base_path'] = base_path if i['object_type']['name'] == 'Task': shot_name = i['parent']['name'] #this may break when it comes to asset builds since they are not nested under a shot.. task_type = i['type']['name'] task_name = i['name'] path = base_path out_path = base_path if task_type in ['Compositing', 'Precomp', 'Cleanplate', 'Retime', 'Rotoscoping', 'Paintout']: comp_out_dir = '02_OUTPUT/03_comp' if task_type.lower() != task_name.lower(): comp_out_dir = '02_OUTPUT/01_precomp/{task_name}'.format(task_name=task_name) path = '{base_path}{dept_name}/{shot_name}/'.format(base_path=base_path,shot_name=shot_name,dept_name='05_COMP') out_path = '{base_path}{dept_name}/{shot_name}/{comp_out_dir}/'.format(base_path=base_path,shot_name=shot_name,dept_name='05_COMP',comp_out_dir=comp_out_dir) if task_type in ['Matchmove', 'Tracking']: path = '{base_path}{dept_name}/scenes/{shot_name}/tracking/'.format(base_path=base_path,shot_name=shot_name,dept_name='04_3D') out_path = '{base_path}{dept_name}/{shot_name}/TRAC/'.format(base_path=base_path,shot_name=shot_name,dept_name='06_RENDERS') if task_type in ['Animation']: path = '{base_path}{dept_name}/scenes/{shot_name}/anim/'.format(base_path=base_path,shot_name=shot_name,dept_name='04_3D') out_path = '{base_path}{dept_name}/{shot_name}/ANIM/'.format(base_path=base_path,shot_name=shot_name,dept_name='06_RENDERS') if task_type in ['Layout']: path = '{base_path}{dept_name}/scenes/{shot_name}/layout/'.format(base_path=base_path,shot_name=shot_name,dept_name='04_3D') out_path = '{base_path}{dept_name}/{shot_name}/LYT/'.format(base_path=base_path,shot_name=shot_name,dept_name='06_RENDERS') if task_type in ['Lighting']: path = '{base_path}{dept_name}/scenes/{shot_name}/lighting/'.format(base_path=base_path,shot_name=shot_name,dept_name='04_3D') out_path = '{base_path}{dept_name}/{shot_name}/FINL/'.format(base_path=base_path,shot_name=shot_name,dept_name='06_RENDERS') if task_type in ['FX']: path = '{base_path}{dept_name}/scenes/{shot_name}/fx/'.format(base_path=base_path,shot_name=shot_name,dept_name='04_3D') out_path = '{base_path}{dept_name}/{shot_name}/FX/'.format(base_path=base_path,shot_name=shot_name,dept_name='06_RENDERS') path = path.replace('//', '/') out_path = out_path.replace('//', '/') if i['custom_attributes']['path']!= path: #only make changes if they dont already exist i['custom_attributes']['path'] = path if i['custom_attributes']['out_path'] != out_path: #only make changes if they dont already exist i['custom_attributes']['out_path'] = out_path session.commit() print("--- %s seconds ---" % (time.time() - start_time)) return { 'success': True, 'message': 'updated task paths!' } def register(session, **kw): '''Register plugin.''' # Validate that session is an instance of ftrack_api.Session. If not, # assume that register is being called from an incompatible API # and return without doing anything. if not isinstance(session, ftrack_api.Session): # Exit to avoid registering this plugin again. return action = UpdatePaths(session) action.register() if __name__ == '__main__': logging.basicConfig(level=logging.INFO) session = ftrack_api.Session() register(session) # Wait for events. session.event_hub.wait()
  3. Works like a charm! Thank you for your prompt reply!
  4. I am working from the 'Example Action' found here. http://ftrack.rtd.ftrack.com/en/3.5.0/developing/actions.htm My end goal is to create directory structures based on Ftrack hiearchy. At the moment, all I am doing is printing some information (object type and name) based on what is selected. Everything works... but when I change the name of the selected task, or its type through Ftrack, and when I run the action again, it returns the information from my selection prior to the changes made. How can I force update the events inside of the launch() function so that it always operates on the latest ftrack information? Here is a very basic version of my code: import logging import ftrack_api import os #os.environ['FTRACK_SERVER'] = ############ #os.environ['FTRACK_API_USER'] = os.environ.get("USERNAME") #os.environ['FTRACK_API_KEY'] = ############ class MyCustomAction(object): '''Custom action.''' label = 'Create Folders' identifier = 'create.initial.folders' description = 'This creates the initial task folders' def __init__(self, session): '''Initialise action.''' super(MyCustomAction, self).__init__() self.session = session self.logger = logging.getLogger( __name__ + '.' + self.__class__.__name__ ) def register(self): '''Register action.''' self.session.event_hub.subscribe( 'topic=ftrack.action.discover and source.user.username={0}'.format( os.environ.get("USERNAME")#self.session.api_user ), self.discover ) self.session.event_hub.subscribe( 'topic=ftrack.action.launch and data.actionIdentifier={0} and ' 'source.user.username={1}'.format( self.identifier, os.environ.get("USERNAME")#self.session.api_user ), self.launch ) def discover(self, event): '''Return action config if triggered on a single asset version.''' data = event['data'] # If selection contains more than one item return early since # this action can only handle a single version. selection = data.get('selection', []) self.logger.info('Got selection: {0}'.format(selection)) #if len(selection) != 1 or selection[0]['entityType'] != 'assetversion': # return return { 'items': [{ 'label': self.label, 'description': self.description, 'actionIdentifier': self.identifier }] } def launch(self, event): ########## How can I update this ^^ event so that launch() doesnt operate on an outdated information ########## ########## ########## '''Callback method for custom action.''' selection = event['data'].get('selection', []) #print selection for entity in selection: item = self.session.get('Task', entity['entityId']) object_type = item['object_type']['name'] name = item['name'] print name, object_type return { 'success': True, 'message': 'Ran my custom action successfully!' } def register(session, **kw): '''Register plugin.''' # Validate that session is an instance of ftrack_api.Session. If not, # assume that register is being called from an incompatible API # and return without doing anything. if not isinstance(session, ftrack_api.Session): # Exit to avoid registering this plugin again. return action = MyCustomAction(session) action.register() if __name__ == '__main__': logging.basicConfig(level=logging.INFO) session = ftrack_api.Session() register(session) # Wait for events. session.event_hub.wait() Thanks! Ali
  5. Oh that's great! I'm glad it didn't give me permission......... I understand my mistake here, and the code now works. Thank you so much for the prompt reply Mattias! Ali
  6. Hello, I am trying to make a python module to change task status for a given task ID I have set my user role settings to have everything enabled as shown in the image. What am I doing wrong? ############################ import ftrack_api session = ftrack_api.Session() assigned_tasks = session.query('select link from Task where assignments any (resource.username = "{0}")'.format(session.api_user)) ''' for task in assigned_tasks: print u' / '.join(item['name'] for item in task['link']), task['id'], task['status']['name'] ''' task_id = "9b8f0400-3324-11e6-8686-02420a280107" def updateTask(task_id,status_name): task = session.query('Task where id is '+task_id+'').one() task['status']['name'] = status_name session.commit() updateTask(task_id,'In Progress') # Result: L:\HAL\LIVEAPPS\apps\Scripts\NUKE/python/ftrack\requests\packages\urllib3\util\ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning. InsecurePlatformWarning ERROR 18:13:29.598:ftrack_api.session.Session(7268): Server reported error: PermissionError(Permission denied: not allowed to 'update' 'TaskStatus'. Missing the required 'Can access settings' permission.) Traceback (most recent call last): File "<string>", line 19, in <module> File "<string>", line 16, in updateTask File "L:\HAL\LIVEAPPS\apps\Scripts\NUKE/python\ftrack_api\session.py", line 1165, in commit result = self._call(batch) File "L:\HAL\LIVEAPPS\apps\Scripts\NUKE/python\ftrack_api\session.py", line 1544, in _call raise ftrack_api.exception.ServerError(error_message) ftrack_api.exception.ServerError: Server reported error: PermissionError(Permission denied: not allowed to 'update' 'TaskStatus'. Missing the required 'Can access settings' permission.) L:\HAL\LIVEAPPS\apps\Scripts\NUKE/python/ftrack\requests\packages\urllib3\util\ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning. InsecurePlatformWarning I have read the API documentation and searched your forums as well... and came across this, but I couldn't make it work for my code. Thanks! Ali