Shotgun API Tips and Tricks Megapost

Filtering records for Entities with a combination of Pipeline Step Statuses

Sometimes you might want to find a series of Entities that are, say, final in lighting but CBB in comp, or ‘in review’ in rigging and not ‘CBB’ for something else. This is very easy to do in the UI, but in the API it can be a little brain-bendy.

To start, let’s use a quick one-liner to find out which steps in our Shot pipeline are visible in a specific Project:

p = {'type':'Project','id':42}
[(k, v['name']['value'], v['visible']['value']) for k,v in sg.schema_field_read('Shot', project_entity=p).iteritems() if k.startswith('step_')]

We’ll get a return of something like:

[('step_133', 'Tracking', True),
 ('step_35', 'Layout', True),
 ('step_106', 'Animation', True),
 ('step_2', 'Online', True),
 ('step_0', 'ALL TASKS', True),
 ('step_7', 'Light', True),
 ('step_8', 'Comp', True),
 ('step_6', 'FX', True),
 ('step_135', 'Environment', False),
 ('step_136', 'CFX', False),
 ('step_134', 'Roto', False)]

Armed with which Steps go with which names, we can construct a filter to query. Here is a simple query that defaults to AND-ing components together. If you want to OR something, you’ll need to use a compound filter syntax like this one.

# find Shots whose Animation is In Review or Final,
# and whose Comp is neither Final nor CBB.
filters = [
    ['step_106.Task.sg_status_list', 'in', ['ir', 'fin']],
    ['step_8.Task.sg_status_list', 'not_in', ['fin', 'cbb']]
]

shots = sg.find('Shot', filters, ['entity'])
7 Likes