Skip to content

pre_ocio_hook

OCIOEnvHook

Bases: PreLaunchHook

Set OCIO environment variable for hosts that use OpenColorIO.

Source code in client/ayon_core/hooks/pre_ocio_hook.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
class OCIOEnvHook(PreLaunchHook):
    """Set OCIO environment variable for hosts that use OpenColorIO."""

    order = 0
    hosts = {
        "substancepainter",
        "substancedesigner",
        "fusion",
        "blender",
        "aftereffects",
        "3dsmax",
        "houdini",
        "maya",
        "nuke",
        "hiero",
        "resolve",
        "openrv",
        "cinema4d",
        "silhouette",
    }
    launch_types = set()

    def execute(self):
        """Hook entry method."""

        folder_entity = self.data["folder_entity"]

        template_data = get_template_data(
            self.data["project_entity"],
            folder_entity=folder_entity,
            task_entity=self.data["task_entity"],
            host_name=self.host_name,
            settings=self.data["project_settings"],
        )

        config_data = get_imageio_config_preset(
            self.data["project_name"],
            self.data["folder_path"],
            self.data["task_name"],
            self.host_name,
            anatomy=self.data["anatomy"],
            project_settings=self.data["project_settings"],
            template_data=template_data,
            env=self.launch_context.env,
            folder_id=folder_entity["id"],
        )

        if not config_data:
            self.log.debug("OCIO not set or enabled")
            return

        ocio_path = config_data["path"]

        if self.host_name in ["nuke", "hiero"]:
            ocio_path = ocio_path.replace("\\", "/")

        self.log.info(
            f"Setting OCIO environment to config path: {ocio_path}")

        self.launch_context.env["OCIO"] = ocio_path

execute()

Hook entry method.

Source code in client/ayon_core/hooks/pre_ocio_hook.py
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
def execute(self):
    """Hook entry method."""

    folder_entity = self.data["folder_entity"]

    template_data = get_template_data(
        self.data["project_entity"],
        folder_entity=folder_entity,
        task_entity=self.data["task_entity"],
        host_name=self.host_name,
        settings=self.data["project_settings"],
    )

    config_data = get_imageio_config_preset(
        self.data["project_name"],
        self.data["folder_path"],
        self.data["task_name"],
        self.host_name,
        anatomy=self.data["anatomy"],
        project_settings=self.data["project_settings"],
        template_data=template_data,
        env=self.launch_context.env,
        folder_id=folder_entity["id"],
    )

    if not config_data:
        self.log.debug("OCIO not set or enabled")
        return

    ocio_path = config_data["path"]

    if self.host_name in ["nuke", "hiero"]:
        ocio_path = ocio_path.replace("\\", "/")

    self.log.info(
        f"Setting OCIO environment to config path: {ocio_path}")

    self.launch_context.env["OCIO"] = ocio_path