Skip to content

Example: Create a new Shot and apply a Task Template

kporangehat edited this page Dec 10, 2010 · 9 revisions

Creating a new Shot with a Task Template is just like linking it to another entity, but Shotgun will apply the Task Template in the background and create the appropriate Tasks on the Shot for you.

Find the Task Template

First we need to find the Task Template we're going to apply. We'll assume you know the name of the Task Template you want to use.

filters = [ ['name','is', '3D Shot Template' ]
template = sg.find_one('TaskTemplate',filters)

Create the Shot

Now we can create the Shot with the link to the TaskTemplate to apply.

data = { 'project': {'type':'Project','id':4},
         'code': '100_010',
         'description': 'dark shot with wicked cool ninjas'
         'task_template': template,
         'user': {'type':'HumanUser', 'id':165} }
result = sg.create('Shot', data)

This will create a new Shot named '100_010' linked to the TaskTemplate '3D Shot Template' and Shotgun will then create the Tasks defined in the Template on the Shot.

  • data is a list of key/value pairs where the key is the column name to update and the value is the value.
  • project and code are required
  • description is just a text field that you might want to update as well
  • task_template is another entity column where we set the Task Template which has the Tasks we wish to create by default on this Shot. We found the specific template we wanted to assign in the previous block by searching

The variable result now contains the hash of the new Shot that was created.

{
    'code': '010_010',
    'description': 'dark shot with wicked cool ninjas',
    'id': 2345,
    'project': {'id': 4, 'name': 'Gunslinger', 'type': 'Project'},
    'task_template': {'id': 12,
                   'name': '3D Shot Template',
                   'type': 'TaskTemplate'},
    'type': 'Shot'
}    

If we now search for the Tasks linked to the Shot, we'll find the Tasks that match our TaskTemplate

tasks = sg.find('Task',filters=[['entity','is',result]])

Now the tasks variable contains the following:

[{'id': 3253, 'type': 'Task'},
 {'id': 3254, 'type': 'Task'},
 {'id': 3255, 'type': 'Task'},
 {'id': 3256, 'type': 'Task'},
 {'id': 3257, 'type': 'Task'}]
Clone this wiki locally