eight Posted February 12, 2016 Report Share Posted February 12, 2016 Is there an easy way to query an entity from an event? My problem is that each item in event['data']['selection'] contains an 'entityType' which is 'task' whether it is a Task, Shot, Sequence, etc. So I don't know whether to do session.get('Task', id), session.get('Shot', id), session.get('Sequence', id) or whatever it might be. How do I know what the actual type to query is? Link to comment Share on other sites More sharing options...
Mike Posted June 28, 2016 Report Share Posted June 28, 2016 I'm curious about this too. I'm trying to turn the create folders example from the bitbucket into a custom action using the new API. I'd like this to work like the original script (action only displays when your selection isn't a 'Task'), but I'm having trouble translating my examples. I'm not familiar enough with the new API. My current new API code: def discover(self, event): '''Return action config if triggered on a single asset version.''' data = event['data'] logger.info('Data create action: {0}'.format(data)) # If selection contains more than one item return early since # this action can only handle a single version. selection = data.get('selection', []) logger.info('Selection discover create action: {0}'.format(selection)) if len(selection) != 1 or selection[0]['entityType'] == 'show': return return { 'items': [{ 'label': self.label, 'description': self.description, 'actionIdentifier': self.identifier }] } Old API code: def discover(self, event): '''Discover the action.''' selection = event['data'].get('selection', []) # Validate selection for item in selection: self.logger.info(u'Validating create folders entity: {0}'.format(item)) # Entities in the project hierarchy are valid, unless they are leafs # (ObjectType is Task) if item.get('entityType') == 'task': entity = ftrack.Task(item.get('entityId')) if not entity or entity.getObjectType() == 'Task': return # Something invalid encountered, return no actions. else: return return { 'items': [{ 'label': self.label, 'actionIdentifier': self.identifier }] } Link to comment Share on other sites More sharing options...
Mattias Lagergren Posted July 4, 2016 Report Share Posted July 4, 2016 Hi, Quote So I don't know whether to do session.get('Task', id), session.get('Shot', id), session.get('Sequence', id) or whatever it might be. How do I know what the actual type to query is? You should be able to use the base class "TypedContext": session.get('TypedContext', id) It will figure out the correct subclass Link to comment Share on other sites More sharing options...
Martin Pengelly-Phillips Posted July 5, 2016 Report Share Posted July 5, 2016 This is important for us too. Currently we have to maintain a mapping of old style type names to new. Ideally we would like ftrack native events to use the new style type names. Link to comment Share on other sites More sharing options...
Mattias Lagergren Posted July 6, 2016 Report Share Posted July 6, 2016 14 hours ago, Martin Pengelly-Phillips said: This is important for us too. Currently we have to maintain a mapping of old style type names to new. Ideally we would like ftrack native events to use the new style type names. Cool! I've made sure that we have a ticket to cover this request. Link to comment Share on other sites More sharing options...
Mike Posted September 26, 2017 Report Share Posted September 26, 2017 I've noticed that the new built-in Maya hooks don't require sessions to query information. How should I go about getting typed contexts and other data that I need? Has this changed at all? Link to comment Share on other sites More sharing options...
kylebjordahl Posted September 27, 2017 Report Share Posted September 27, 2017 On 7/4/2016 at 2:29 AM, Mattias Lagergren said: Hi, You should be able to use the base class "TypedContext": session.get('TypedContext', id) It will figure out the correct subclass will this work on query() as well as get()? Link to comment Share on other sites More sharing options...
Mattias Lagergren Posted October 2, 2017 Report Share Posted October 2, 2017 On 27/09/2017 at 11:03 PM, kylebjordahl said: will this work on query() as well as get()? Yes, you will be able to use the base class (Context, TypedContext) in both get and query. Behind the scenes get uses query if it is not in the cache. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.