Querying Shot's Tasks using Shot ID or Shot Name

1. When Shot ID is known (let's say it is 860) it is quite easy to query the Shot Name using the following syntax.

myShot = sg.find("Shot", filters=[['id', 'is', 860]], fields = ['code'])

print myShot[0]['code']

STDOUT: shot_01

2. Is there a quick way to query the linked to this Shot Tasks when both Shot Name and Shot ID are known?

I can query the Tasks using all kind of fields. But I can't find the way to filter only those Tasks that are assigned to a particular shot.

The Task's field that is used to store the data to what Shot Name the Task belongs to is stored in Dictionary form:

The field itself is called as 'entity'. This 'entity' field is actually an array of all kind of values one of which is the Shot Name the task is assigned to.

Here is the example on how the Tasks's entity field looks like:

tasks = sg.find("Task", filters=[['sg_status_list', 'is', 'ip']], fields = ['entity'])

print len(tasks)





{'entity': {'id': 2, 'name': 'shot_010', 'type': 'Shot'}, 'id': 6, 'type': 'Task'},

{'entity': {'id': 2, 'name': 'shot_010', 'type': 'Shot'}, 'id': 7, 'type': 'Task'},

{'entity': {'id': 2, 'name': 'shot_010', 'type': 'Shot'}, 'id': 8, 'type': 'Task'},

{'entity': {'id': 5, 'name': 'shot_040', 'type': 'Shot'},'id': 41,'type': 'Task'},

{'entity': {'id': 6, 'name': 'shot_050', 'type': 'Shot'},'id': 50,'type': 'Task'},

.........>>skipping an entire list here........

{'entity': {'id': 627, 'name': 'teapot', 'type': 'Asset'},'id': 162,'type': 'Task'}



I see it is possible to print out the individual Key value out of this Dictionary using this syntax:



STDOUT: 'shot_010'


But I can't use this syntax used to print out the Tasks's Entity's Field's 'name' key value while querying with

sg.find_one command. It will give me the error if I attempt to do this:


shotTasks = sg.find("Task", filters=[['sg_status_list', 'is', 'ip'], fields= ['['entity']['name']', 'is', 'shot_010'])

STDOUT: # Error: SyntaxError: invalid syntax #


7 条评论

  • 0

    I figure out the way to query the Task assigned to the shot starting with known Shot ID number.

    # First query the Shot Name which is stored in Shot's 'code' field:

    myShot = sg.find_one("Shot", filters=[['id', 'is', 860]], fields = ['code'])

    print myShot

    STDOUT: {'code': 'shot_01', 'type': 'Shot', 'id': 860}

    # Now time to query the Tasks connected to this Shot:

    shotTasks = sg.find("Task", filters=[['entity', 'is', myShot]], fields= ['code'])

    print shotTasks

    STDOUT: [{'type': 'Task', 'id': 160}]


    As you can see from this example when we query Task we set the filter argument to 'entity'

    which set to 'is' myShot. Interesting that myShot is a Dictionary String with a length of 3.

    print len(myShot)

    STDOUT: 3

    print myShot['code']

    STDOUT: shot_01

    print myShot['type']

    STDOUT: shot

    print myShot['id']

    STDOUT: 860

    So when we query Task specifying a filter to

    filters=[['entity', 'is', myShot]]

    we actually set three filters "statements":

    ['entity', 'is', myShot['code']

    ['entity', 'is', myShot['type']

    ['entity', 'is', myShot['id']

    Please note the syntax above is incorrect. Since it is going give you an error if you attempt to query a TASK with the filter= set to:

    shotTasks = sg.find("Task", filters=[['entity', 'is', myShot['code']], fields= ['code'])


    It will also give the error when the data is sent via variable:


    myShot = sg.find_one("Shot", filters=[['id', 'is', 860]], fields = ['code'])

    tempVariable = myShot['code']

    shotTasks = sg.find("Task", filters=[['entity', 'is', tempVariable], fields= ['code'])

    print shotTasks


    It looks like the filter =['entity', 'is', HERE] sintax is very restricting. It does accept the  Dictionary String Variables. But it wont accept anything else.

    # XMLRPC Fault 103:

    # # API read() Task.entity expected [Hash, NilClass] data type(s) but got String:


  • 0
    Kym Watts

    He y Sputniks,


    I use the following snippet to get both the notes and the tasks that are associated with the shot.


    filter = [['code','is', shotCode],['project','is',{'type':'Project','id':64}]]

    #things about the shot i want back from sg

    infoFromSG = ['id','notes','tasks']

    dictFromSG = sg.find_one('Shot',filter,infoFromSG )


    Hope this helps.



  • 0

    What value do you assign to shotCode variable used in

    filter = [['code','is', shotCode],['project','is',{'type':'Project','id':64}]]


  • 0
    Kym Watts
    Hey, It will be something like : shotCode = 'shot_001' Cheers Kym
  • 0
    Kym Watts

    I have reajusted my code for your shot, I should have done this last night:

        filter = [['code','is', 'shot_01'],['project','is',{'type':'Project','id':64}]]
        #things about the shot i want back from sg
        infoFromSG = ['tasks']
        dictFromSG = sg.find_one('Shot',filter,infoFromSG )
       # Then your return is a list of dictionaries and would look something like this:

        dictFromSG = {'id': 864,
     'tasks': [{'id': 4311, 'name': 'Animation', 'type': 'Task'},
               {'id': 1725, 'name': 'Compositing', 'type': 'Task'},
               {'id': 1493, 'name': 'Lighting', 'type': 'Task'},
                'type': 'Shot'}

    Hope that explains it much better.



  • 0

    Interesting. Would you please clarify the syntax used in your filter's definition (indicated with the bold font):

    filter = [['code','is', shotCode],['project','is',{'type':'Project','id':64}]]

    Let's break the filter definition down to two parts:

    filter =[               ['code','is', shotCode],        ['project','is',    {'type':'Project','id':64}]                  ]

    What is {'type':'Project','id':64}  ?

    It appears to me it is a Dictionary String with two keys defined: 'type' and 'id'.

    What does Shotgun returns from this filter's request? Does it return a Project's 'name'?

    I would like to know how Shotgun process this filter:

    filter = [['code','is', shotCode],['project','is',{'type':'Project','id':64}]]

    What the first part of the filter definition


    expects from the second part:


  • 0
    Marc Dubrois

    You can also use this syntax.

    filters = [ ['code','is', "shot_01"], ['project.Project.name','is', "PROJECT_NAME"] ]

    With this syntax, you skip one request for find the project id.