Created
February 4, 2026 10:45
-
-
Save BigRoy/6036f9ebcef130c3953af858568d1a83 to your computer and use it in GitHub Desktop.
Quick 'n' dirty way to expose simple means to set a representation's colorspace. Run this in admin console in tray launcher, then when opening tray browser it should show an action to "Change Representation Colorspace" - use the OPTION BOX to set a new one.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import ayon_api | |
| from ayon_core.lib import TextDef, UILabelDef | |
| from ayon_core.pipeline import register_loader_plugin, LoaderPlugin | |
| from ayon_core.pipeline.colorspace import get_ocio_config_colorspaces | |
| from ayon_core.pipeline.load import LoadError | |
| class ChangeColorspaceLoader(LoaderPlugin): | |
| label = "Change Representation Colorspace" | |
| product_types = ["*"] | |
| representations = ["*"] | |
| order = 0.0 | |
| color = "#FF0000" | |
| @staticmethod | |
| def _get_representation_colorspace(context) -> str: | |
| repre_data = context["representation"]["data"] | |
| colorspace_data: dict = repre_data.get("colorspaceData", {}) | |
| return colorspace_data.get("colorspace", "") | |
| @classmethod | |
| def get_options(cls, contexts): | |
| # Current colorspace | |
| colorspace = "" | |
| for context in contexts: | |
| context_colorspace = cls._get_representation_colorspace(context) | |
| if context_colorspace: | |
| colorspace = context_colorspace | |
| break | |
| return [ | |
| UILabelDef("Set colorspace name."), | |
| TextDef("colorspace", | |
| tooltip="Colorspace to set.", default=colorspace) | |
| ] | |
| def load(self, context, name, namespace, options): | |
| print(options) | |
| if not options: | |
| raise LoadError( | |
| "No options were provided. Please use the Option Box." | |
| ) | |
| # Set the representation colorspace data and apply with ayon API | |
| repre_data = context["representation"]["data"] | |
| colorspace_data: dict = repre_data.get("colorspaceData", {}) | |
| if not colorspace_data: | |
| self.log.info( | |
| f"No colorspace data found for representation " | |
| f"'{context['representation']['name']}'. Skipping." | |
| ) | |
| return | |
| colorspace: str = options.get("colorspace", "") | |
| if not colorspace: | |
| self.log.error("No colorspace value was provided in options.") | |
| return | |
| # Confirm the value does actually exist in the OCIO config | |
| ocio_colorspaces = get_ocio_config_colorspaces( | |
| colorspace_data["config"]["path"] | |
| )["colorspaces"] | |
| if ( | |
| colorspace not in ocio_colorspaces | |
| and not f"role_{colorspace}" in ocio_colorspaces | |
| ): | |
| raise LoadError( | |
| f"Colorspace '{colorspace}' not found in OCIO config. " | |
| f"Available colorspaces: {', '.join(ocio_colorspaces)}" | |
| ) | |
| if colorspace == colorspace_data.get("colorspace", ""): | |
| self.log.info( | |
| f"Representation '{context['representation']['name']}' " | |
| f"already has colorspace '{colorspace}'. Skipping." | |
| ) | |
| return | |
| colorspace_data["colorspace"] = colorspace | |
| # Update representation data | |
| ayon_api.update_representation( | |
| project_name=context["project"]["name"], | |
| representation_id=context["representation"]["id"], | |
| data=repre_data | |
| ) | |
| register_loader_plugin(ChangeColorspaceLoader) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment