/ Published in: Python
                    
                                        
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
import sys
from pprint import pprint
#sys.path.append ('z:/software/scripts')
# you need to either append the path to where the shotgun api is or
#you need to add it to your PYTHONPATH as i have done at home
#from getShotData import *
print ('Loading Shotgun Support')
URL = ""
name = ""
API = ""
# connect to shotgun
def shotgunConnect():
from shotgun_api3_preview import Shotgun
sg = Shotgun(URL,name,API)
return sg
# find a project given the name
def sgProject (sg, input):
return sg.find_one("Project", [["name", "is", input]] )
# finding a shot given the name :
def sgShot (sg, shot, project):
return sg.find_one('Shot',[['code','is',shot],['project','is',project]],['sg_cut_in','sg_cut_out','sg_client_version', 'code'])
# expects a project in the proper naming, and a shot
def createShot (sg, proj, shot):
filters = [['code','is','CGI / Live Action Shot' ]]
template = sg.find_one('TaskTemplate',filters)
project = sgProject(proj)
data = { 'project': {"type":"Project","id": project['id']},
'code': shot,
'task_template' : template,
'description': '',
'sg_status_list': 'wtg' }
result = sg.create('Shot', data)
return result
# find multiple notes given a shot ID (from above)
# order in newest to oldest
# requires you call it like note[0]['content']
def sgNotesFind (sg, shotID):
print shotID
note = sg.find('Note',[['note_links','is', shotID]],['subject','content', 'created_at'],[{'field_name':'created_at','direction':'desc'}])
return note
# find a single (most recent) note given a shot ID
# then call it like note['content']
def sgNotesFindLatest (sg, shotID):
note = sg.find_one('Note',[['note_links','is', shotID][0]],['subject','content','created_at'],[{'field_name':'created_at','direction':'desc'}])
return note
def sgCreateNote(sg, project, shotID, subject, content):
# enter data here for a note to create
data = {'subject':subject,'content':content,'note_links':[shotID],'project':project}
# create the note
noteID = sg.create('Note',data)
return noteID
# create a version
def sgCreateVersion(sg, project, shotID, verName, description, framePath, firstFrame, lastFrame, clientName=''):
data = {'project': project,
'code': verName,
'description': description,
'sg_path_to_frames': framePath,
'frame_range': firstFrame + '-' + lastFrame,
#'sg_uploaded_movie': '/Users/throb/Downloads/test.m4v',
#'sg_first_frame': 1,
#'sg_last_frame': 100,
'sg_status_list': 'rev',
'entity': shotID}
# in case we're putting a client version in here we need this code.
# we are expecting a field called sg_client_name in the version table.
# please make sure you create this in the shotgun setup
if clientName != '' :
data['sg_client_name'] = clientName
#'user': {'type':'HumanUser', 'id':165} }
return sg.create('Version',data)
#add a task version to the system
def sgCreateVersionTask(sg, project, shotID, verName, description, framePath, firstFrame, lastFrame, task):
filters = [['content','is',task],['entity','is',shot]]
taskID = sg.find_one('Task',filters)
data = {'project': project,
'code': verName,
'description': description,
'sg_path_to_frames': framePath,
'frame_range': firstFrame + '-' + lastFrame,
#'sg_uploaded_movie': '/Users/throb/Downloads/test.m4v',
#'sg_first_frame': 1,
#'sg_last_frame': 100,
'sg_status_list': 'rev',
'sg_task': taskID,
'entity': shotID}
# in case we're putting a client version in here we need this code.
# we are expecting a field called sg_client_name in the version table.
# please make sure you create this in the shotgun setup
#'user': {'type':'HumanUser', 'id':165} }
return sg.create('Version',data)
# look for versions in a shot:
def sgVersionFind(sg, shotID):
return sg.find('Version',[['entity','is',shotID]],['code','task','sg_path_to_frames'],[{'field_name':'created_at','direction':'desc'}])
def sgVersionFindLatest(sg, shotID):
return sg.find_one('Version',[['entity','is',shotID]],['code','task','sg_path_to_frames'],[{'field_name':'created_at','direction':'desc'}])
# search for the latest task given shotID and task info
def sgVersionFindLatestTask(sg, shotID, task):
# first look for the task and get the ID
filters = [['content','is',task],['entity','is',shotID]]
taskID = sg.find_one('Task',filters)
# then look for the latest
#version using the task ID. note that we need to use the [0] or else we're sending the array versus the hash
versionLatest = sg.find_one('Version',[['entity','is',shotID],['sg_task','is',taskID]],['code','sg_task','sg_path_to_frames'],[{'field_name':'created_at','direction':'desc'}])
return versionLatest
## The following requires a field called "client_version" be added to shotgun
def sgVersionClientUpate (sg, shotID, version):
data = { 'sg_client_version': version}
result = sg.update('Shot', shotID['id'], data)
return result
# Upload a file to shotgun in the 'sg_qt' field.
# If you do this for a shot, you will need to add this to a field
# Shotgun provides the sg_qt for versions automatically
def sgQTUpload (sg,entity,itemID,path):
# Make sure first letter is capitalized
entity = entity[:1].upper() + entity[1:]
# upload that mother
result = sg.upload (entity, itemID['id'], path,'sg_qt')
return results
# connect to shotgun and get the latest "client version" number
def sgGetClientVersion (shotgunShot):
try :
currentVersion = shotgunShot['sg_client_version']
except :
currentVersion = 0
if currentVersion == None:
return 0
return currentVersion
Comments
 Subscribe to comments
                    Subscribe to comments
                
                