Basic access to SG API - Nuke/ Maya/ Stand-alone

Hello fellow SG community members
Total newbie here ( yes not exactly the best ice breaker! )
I’m working in a studio without an experienced pipeline team and have had to basically become a TD. One area I’m trying to improve on now is accessing and using SG data for Nuke and Maya, and how to access the engine outside software environment to help with building some simple tools.
Not looking for anything crazy right now… just want to understand the basics of for example how to access the frame range of a shot and have been struggling to find a resource that’s easy to understand. Is there anyone kind enough out there to put me in the right path?

Many thnaks!

So there are various ways to get data depending on what it is.

There is the REST and Python api, for interacting with the database.
There is Toolkit which is a framework to build (GUI) applications on and that can be used as the basis for asset management/file management/file structure management.

To get the framerange of a shot you would only need one of the first two since you are pulling data from the database.

Example in python:

# connect to ShotGrid via the api and get a shotgun handle
import shotgun_api3
shotgun = shotgun_api3.Shotgun(xxxxxxxx)

# ask the database for info for a specific record
filters = [["id", "is", 2500]] # replace the number with the id number of the shot you want data from

# what data fields do we want to receive back?
fields = ["sg_cut_in", "sg_cut_out"] # the "cut in" and "cut out" fields codenames
shot_data = shotgun.find_one("Shot", filters, fields)

if you print shot_data you get something like this:

{
    "type": "Shot",
    "id": 2500,
    "sg_cut_in": 1009,
    "sg_cut_out": 1029,
}

Hope this helps!

If you run the zero-config or basic toolkit (i.e. run your applications from ShotGrid Desktop or ShotGrid Create) you should be able to launch the ShotGrid Python Console where you get provided the shotgun, context and tk handles.

From inside a DCC that runs Toolkit (the ShotGrid menu is visible) you could import sgtk inside the python console of that app.

Then to get the running engine you can get this via this code:

import sgtk
engine = sgtk.platform.current_engine()

You can now access your context, tk and shotgun handles like so:

engine.context
engine.shotgun
engine.sgtk