New API : Query Event Entity ID
3 3

8 posts in this topic

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?

Share this post


Link to post
Share on other sites

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
			}] 
		}

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
3 3