Connect shotgun API from inside DCC

Is there a convenience method to get the Shotgun API when you are inside a DCC launched from SG Desktop? I do not want to have to run:

sg = shotgun_api3.Shotgun(SITE_URL, SCRIPT_NAME, API_KEY)

…every time I wish to get an instance of sg. Say I launch Maya through the Desktop and jump into the Python script editor. Shotgun should already be connected and authenticated through the Desktop login. Is there a quick way to get sg where I can then run sg.find_one(...)?

2 Likes

Hey! Take a look at the code snippet in this post:

The engine object has a shotgun property, which is a handle to the Shotgun API, so you can get to it via sgtk.platform.current_engine().

3 Likes

Thanks @tannaz! I remember Stephen Chiu and Mark Thielen mentioning this when I was at WB, but we never used SG Desktop to launch DCCs, so I never looked into it.

2 Likes