Jump to content

New API: Query entity type

Recommended Posts

I'm trying to figure out how to query what an item is based on user selection.  In my tool, a user might be selecting a Sequence, Task, Shot, etc and I'd like different things to happen based on their selection.  Is there any way to query this with the new API?  The docs seem to just show how to query something only if you know exactly what entity type you want.

I have this right now:

dir_contents = []
for item in project['children']:
	dir_contents.append( item )
for item in dir_contents:
	item_name = item['name']
	item_type = item['context_type']
	item_id   = item['id']

When I tested this code out by selecting a Sequence entity, I printed out every attribute and expected to find 'sequence' as a value somewhere, but only the attribute, context_type, resulted in something close to what I was looking for ( print item['context_type'] resulted in 'task' as a value )

Thanks for any help!

Link to post
Share on other sites

Hi Mike,

There is two abstract types in the API schema which represent objects in the project hierarchy.

  • Context - Can be either a Project, or a TypedContext
  • TypedContext - An object in the project hierarchy: e.g. a Folder, Task or Sequence.

A TypedContext will have a object_type relation to an ObjectType entity.  This entity will in turn have some information about which kind of object it is. The object_type information is used behind the scene to generate the dynamic types in the API.

Below is an example how you can use this information:

>>> sequence = session.query('Sequence').first()
>>> print sequence.entity_type
>>> print sequence['object_type']['name']
>>> print isinstance(sequence, session.types['Sequence'])



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
  • Create New...