Sgtk toolkit instance in RV (ocio color management)

Hi,

I’m working on the OCIO color management in RV 2024.1.0

I have read the community posts about linking RV and Shotgrid, (thanks @mmoshev @patrickwolf @nedwilson)

What I got working so far is:
Using the init_hook, I set the RV_SUPPORT_PATH env var, so that a custom “rv_ocio_setup.py” is loaded when launching RV from SG Desktop (“Jump to Screening Room in RV”). I can confirm that this works (print commands I set in my rv_ocio_setup are displayed in RV’s console)

I plan to customize the ocio_config_from_media and ocio_node_from_media methods

I would like to instantiate a tk object inside the rv_ocio_setup (using the centralized core of the current project - we use a separate core and pipeline config per project). I’m not sure if I will need to query SG (I’ll probably avoid that for performance reasons) but I will need to use the template system to retrieve the Shot entity from the media path.

I tried a few ways to instantiate a tk object but with no succes.

In rv_ocio_setup.py, I tried bootstrapping:


from rv import rvtypes, commands, extra_commands
import os, re, sys
import PyOpenColorIO as OCIO
import importlib

import sgtk
user = sgtk.authentication.deserialize_user(os.environ.get("SHOTGUN_DESKTOP_CURRENT_USER"))
sgtk.set_authenticated_user(user)

# Toolkit init
mgr = sgtk.bootstrap.ToolkitManager(user)
mgr.base_configuration = "sgtk:descriptor:app_store?name=tk-config-basic"
mgr.plugin_id = "basic.*"
engine = mgr.bootstrap_engine("tk-shell", entity={"type": "Project", "id": 3099})

This is not working, the engine variable is empty

I then tried another way :

from rv import rvtypes, commands, extra_commands
import os, re, sys
import PyOpenColorIO as OCIO
import importlib

sys.path.remove(r"C:\Program Files\Autodesk\RV-2024.1.0\lib\site-packages")
my_core = r'\\VSERVER01\shotgun\donatdev2024\install\core\python'
sys.path.insert(0, my_core)
import sgtk
tk = sgtk.sgtk_from_entity("Project", 3099)

Does anyone know how to instantiate a tk object inside this rv_ocio_setup.py script ?

Regards

The first is definitely preferable, using the bootstrap manager.
There must be an error displayed, if engine is empty? Otherwise it doesn’t make sense. You could dive in the ToolkitManager code with the debugger a bit, it is not huge.

In the second example, right after import sgtk you have to do sgtk.set_authenticated_user(user), before instantiating toolkit.

You should also look at ShotgunAuthenticator.

2 Likes