Skip to content

Instantly share code, notes, and snippets.

@kporangehat
Created March 15, 2016 00:42
Show Gist options
  • Save kporangehat/4094a8d4896f1432edfa to your computer and use it in GitHub Desktop.
Save kporangehat/4094a8d4896f1432edfa to your computer and use it in GitHub Desktop.
Shotgun Toolkit register_publish() example
"""
Bootstrap script to use for registering a publish. Includes authentication and assumes file
is already in the correct location in the directory structure and is named correctly to match
an appropriate template.
"""
import sys
# Append path to your studio core location so sgtk can be imported. If you don't have a studio
# core, you can use the project-specific core location for the files you're publishing.
sys.path.append("/sgtk/software/shotgun/studio/install/core/python")
import sgtk
# Import the ShotgunAuthenticator from the tank_vendor.shotgun_authentication
# module. This class allows you to authenticate either programmatically or, in this
# case, interactively.
from tank_vendor.shotgun_authentication import ShotgunAuthenticator
# Setup authentication
# you will be prompted for your username/password. If you would rather run this with script-based
# authentication, you can follow the instructions in our knowledge base
# See https://support.shotgunsoftware.com/entries/95445997
cdm = sgtk.util.CoreDefaultsManager()
authenticator = ShotgunAuthenticator(cdm)
authenticator.clear_default_user()
user = authenticator.get_user()
sgtk.set_authenticated_user(user)
# Bookstrap Toolkit
tk = sgtk.sgtk_from_path(file_to_publish)
# Required to ensure the local path cache is up to date when creating a context from a path on disk
tk.synchronize_filesystem_structure()
ctx = tk.context_from_path(file_to_publish)
# Publish your file
# You can add more logic to provide additional parameters like task (recommended), thumbnail,
# comment, dependencies, etc.
# See: https://support.shotgunsoftware.com/entries/95441117-Core-API-Reference#register_publish
file_to_publish = "/sgtk/projects/pied_piper/sequences/001/100b/Comp/publish/nuke/scene.v001.nk"
sg_data = sgtk.util.register_publish(tk=tk,
context=ctx,
path=file_to_publish,
name="scene",
version=1,
published_file_type="Nuke Script")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment