Jump to content

New API : Query Event Entity ID


eight

Recommended Posts

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

  • 4 months later...

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

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

  • 1 year later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...