Skip to content

load_frames

Loader for image sequences and single frames in OpenRV.

FramesLoader

Bases: LoaderPlugin

Load frames into OpenRV.

Source code in client/ayon_openrv/plugins/load/openrv/load_frames.py
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
class FramesLoader(load.LoaderPlugin):
    """Load frames into OpenRV."""

    label = "Load Frames"
    product_types: ClassVar[set] = {"*"}
    representations: ClassVar[set] = {"*"}
    extensions: ClassVar[set] = {ext.lstrip(".") for ext in IMAGE_EXTENSIONS}
    order = 0

    icon = "code-fork"
    color = "orange"

    def load(self,
             context: dict,
             name: Optional[str] = None,
             namespace: Optional[str] = None,
             options: Optional[dict] = None) -> None:
        """Load the frames into OpenRV."""
        sequence = rv.commands.sequenceOfFile(
            self.filepath_from_context(context))

        namespace = namespace or context["folder"]["name"]

        loaded_node = rv.commands.addSourceVerbose([sequence[0]])

        # update colorspace
        self.set_representation_colorspace(loaded_node,
                                           context["representation"])

        imprint_container(
            loaded_node,
            name=name,
            namespace=namespace,
            context=context,
            loader=self.__class__.__name__
        )

    def update(self, container: dict, context: dict) -> None:
        """Update loaded container."""
        node = container["node"]

        filepath = rv.commands.sequenceOfFile(
            self.filepath_from_context(context))[0]

        repre_entity = context["representation"]

        # change path
        rv.commands.setSourceMedia(node, [filepath])

        # update colorspace
        self.set_representation_colorspace(node, context["representation"])

        # update name
        rv.commands.setStringProperty(
            f"{node}.media.name", ["newname"], allowResize=True)
        rv.commands.setStringProperty(
            f"{node}.media.repName", ["repname"], allowResize=True)
        rv.commands.setStringProperty(
            f"{node}.openpype.representation",
            [repre_entity["id"]], allowResize=True
        )

    def remove(self, container: dict) -> None:  # noqa: PLR6301
        """Remove loaded container."""
        node = container["node"]
        group = rv.commands.nodeGroup(node)
        rv.commands.deleteNode(group)

    @staticmethod
    def set_representation_colorspace(node: str, representation: dict) -> None:
        """Set colorspace based on representation data."""
        colorspace_data = representation.get("data", {}).get("colorspaceData")
        if colorspace_data:
            colorspace = colorspace_data["colorspace"]
            # TODO: Confirm colorspace is valid in current OCIO config
            #   otherwise errors will be spammed from OpenRV for invalid space

            group = rv.commands.nodeGroup(node)

            # Enable OCIO for the node and set the colorspace
            set_group_ocio_active_state(group, state=True)
            set_group_ocio_colorspace(group, colorspace)

load(context, name=None, namespace=None, options=None)

Load the frames into OpenRV.

Source code in client/ayon_openrv/plugins/load/openrv/load_frames.py
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
def load(self,
         context: dict,
         name: Optional[str] = None,
         namespace: Optional[str] = None,
         options: Optional[dict] = None) -> None:
    """Load the frames into OpenRV."""
    sequence = rv.commands.sequenceOfFile(
        self.filepath_from_context(context))

    namespace = namespace or context["folder"]["name"]

    loaded_node = rv.commands.addSourceVerbose([sequence[0]])

    # update colorspace
    self.set_representation_colorspace(loaded_node,
                                       context["representation"])

    imprint_container(
        loaded_node,
        name=name,
        namespace=namespace,
        context=context,
        loader=self.__class__.__name__
    )

remove(container)

Remove loaded container.

Source code in client/ayon_openrv/plugins/load/openrv/load_frames.py
78
79
80
81
82
def remove(self, container: dict) -> None:  # noqa: PLR6301
    """Remove loaded container."""
    node = container["node"]
    group = rv.commands.nodeGroup(node)
    rv.commands.deleteNode(group)

set_representation_colorspace(node, representation) staticmethod

Set colorspace based on representation data.

Source code in client/ayon_openrv/plugins/load/openrv/load_frames.py
84
85
86
87
88
89
90
91
92
93
94
95
96
97
@staticmethod
def set_representation_colorspace(node: str, representation: dict) -> None:
    """Set colorspace based on representation data."""
    colorspace_data = representation.get("data", {}).get("colorspaceData")
    if colorspace_data:
        colorspace = colorspace_data["colorspace"]
        # TODO: Confirm colorspace is valid in current OCIO config
        #   otherwise errors will be spammed from OpenRV for invalid space

        group = rv.commands.nodeGroup(node)

        # Enable OCIO for the node and set the colorspace
        set_group_ocio_active_state(group, state=True)
        set_group_ocio_colorspace(group, colorspace)

update(container, context)

Update loaded container.

Source code in client/ayon_openrv/plugins/load/openrv/load_frames.py
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
def update(self, container: dict, context: dict) -> None:
    """Update loaded container."""
    node = container["node"]

    filepath = rv.commands.sequenceOfFile(
        self.filepath_from_context(context))[0]

    repre_entity = context["representation"]

    # change path
    rv.commands.setSourceMedia(node, [filepath])

    # update colorspace
    self.set_representation_colorspace(node, context["representation"])

    # update name
    rv.commands.setStringProperty(
        f"{node}.media.name", ["newname"], allowResize=True)
    rv.commands.setStringProperty(
        f"{node}.media.repName", ["repname"], allowResize=True)
    rv.commands.setStringProperty(
        f"{node}.openpype.representation",
        [repre_entity["id"]], allowResize=True
    )