I’m trying programmatically set, enable or disable the OCIO colorspace for added media but have been unable to make it work.
In pseudocode this is what I’d like to do:
loaded_node = rv.commands.addSourceVerbose([filepath])
group = rv.commands.nodeGroup(loaded_node)
# Below are psuedocode functions of what I'd like to do
# (not necessarily in this order or together)
enable_group_ocio(group)
set_group_ocio_colorspace(group, "acescg")
disable_group_ocio(group)
My set_group_ocio_colorspace
prototype
I’ve been able to get set_group_ocio_colorspace
working but ONLY if the group already has OCIO active. I have been unable to activate/deactivate the OCIO pipeline like the OCIO top level menu in RV allows you to do.
import rv
def group_member_of_type(group_node, member_type):
for node in rv.commands.nodesInGroup(group_node):
if rv.commands.nodeType(node) == member_type:
return node
def get_group_ocio_file_node(group):
"""Return OCIOFile node from source group"""
pipeline = group_member_of_type(group, "RVLinearizePipelineGroup")
if pipeline:
return group_member_of_type(pipeline, "OCIOFile")
def set_group_ocio_colorspace(group, colorspace):
"""Set the group's OCIOFile node ocio.inColorSpace property."""
import ocio_source_setup # noqa, RV OCIO package
node = get_group_ocio_file_node(group)
if not node:
raise RuntimeError("Unable to find OCIOFile node for {}".format(group))
rv.commands.setStringProperty(
f"{node}.ocio.inColorSpace", [colorspace], True
)
# Example usage
loaded_node = rv.commands.addSourceVerbose([filepath])
group = rv.commands.nodeGroup(loaded_node)
set_group_ocio_colorspace(group, "ACES - ACEScg")
How to enable/disable OCIO for a group using Python?
It seems the ocio_source_setup.py
implementation has a OCIOSourceSetupMode.useDisplayOCIO
and OCIOSourceSetupMode.disableDisplayOCIO
method which is basically exactly what I’d like to call. However, I would need access to the initialized mode class to be able to call that.
If I were to rewrite this logic in my own library (which I’d then need to maintain to stay sync in behavior to ocio_source_setup.py
so I’d rather not) then I’ll run into the issue that OCIOSourceSetupMode
instances internally cache the state of whether a group is OCIO
enabled or not. As such, that cache would then turn invalid as soon as I start adjusting that on my own without going to the OCIOSourceSetupMode
instance.
Additional context
- I’ve read the Getting started with OCIO in RV topic.
- The question I’m asking here seems to be the same question as asked here in “Need help enabling the OCIO node through python” but aside of pointing to other topics that topic does not seem to present a solution.
- I also posted this question on the ASFW slack in the
#open-review-initiative
here - I’m aware that I can define custom
ocio_config_from_media
andocio_node_from_media
functions in arv_ocio_setup.py
file however as far as I’m aware that’s only used on adding media sources and there’s still no way to explicitly set a colorspace at another point in time from Python.