Skip to content

load_imagesequence

Loader for image sequences.

ImageSequenceLoader

Bases: LoaderPlugin

Load image sequences.

Stores the imported product in a container named after the product.

Source code in client/ayon_harmony/plugins/load/load_imagesequence.py
 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
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
class ImageSequenceLoader(load.LoaderPlugin):
    """Load image sequences.

    Stores the imported product in a container named after the product.
    """

    product_types = {
        "shot",
        "render",
        "image",
        "plate",
        "reference",
        "review",
    }
    representations = {"*"}
    extensions = {"jpeg", "png", "jpg"}
    settings_category = "harmony"

    def load(self, context, name=None, namespace=None, data=None):
        """Plugin entry point.

        Args:
            context (:class:`pyblish.api.Context`): Context.
            name (str, optional): Container name.
            namespace (str, optional): Container namespace.
            data (dict, optional): Additional data passed into loader.

        """
        fname = Path(self.filepath_from_context(context))
        self_name = self.__class__.__name__
        collections, remainder = clique.assemble(
            os.listdir(fname.parent.as_posix())
        )
        files = []
        if collections:
            for f in list(collections[0]):
                files.append(fname.parent.joinpath(f).as_posix())
        else:
            files.append(fname.parent.joinpath(remainder[0]).as_posix())

        folder_name = context["folder"]["name"]
        product_name = context["product"]["name"]

        group_id = str(uuid.uuid4())
        read_node = harmony.send(
            {
                "function": f"AyonHarmony.Loaders.{self_name}.importFiles",  # noqa: E501
                "args": [
                    files,
                    folder_name,
                    product_name,
                    1,
                    group_id
                ]
            }
        )["result"]

        return harmony.containerise(
            f"{folder_name}_{product_name}",
            namespace,
            read_node,
            context,
            self_name,
            nodes=[read_node]
        )

    def update(self, container, context):
        """Update loaded containers.

        Args:
            container (dict): Container data.
            context (dict): Representation context data.

        """
        self_name = self.__class__.__name__
        node = container.get("nodes").pop()

        repre_entity = context["representation"]
        path = get_representation_path(repre_entity)
        collections, remainder = clique.assemble(
            os.listdir(os.path.dirname(path))
        )
        files = []
        if collections:
            for f in list(collections[0]):
                files.append(
                    os.path.join(
                        os.path.dirname(path), f
                    ).replace("\\", "/")
                )
        else:
            files.append(
                os.path.join(
                    os.path.dirname(path), remainder[0]
                ).replace("\\", "/")
            )

        harmony.send(
            {
                "function": f"AyonHarmony.Loaders.{self_name}.replaceFiles",
                "args": [files, node, 1]
            }
        )

        # Colour node.
        if is_representation_from_latest(repre_entity):
            harmony.send(
                {
                    "function": "AyonHarmony.setColor",
                    "args": [node, [0, 255, 0, 255]]
                })
        else:
            harmony.send(
                {
                    "function": "AyonHarmony.setColor",
                    "args": [node, [255, 0, 0, 255]]
                })

        harmony.imprint(
            node, {"representation": repre_entity["id"]}
        )

    def remove(self, container):
        """Remove loaded container.

        Args:
            container (dict): Container data.

        """
        node = container.get("nodes").pop()
        harmony.send(
            {"function": "AyonHarmony.deleteNode", "args": [node]}
        )
        harmony.imprint(node, {}, remove=True)

    def switch(self, container, context):
        """Switch loaded representations."""
        self.update(container, context)

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

Plugin entry point.

Parameters:

Name Type Description Default
context

class:pyblish.api.Context): Context.

required
name str

Container name.

None
namespace str

Container namespace.

None
data dict

Additional data passed into loader.

None
Source code in client/ayon_harmony/plugins/load/load_imagesequence.py
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
def load(self, context, name=None, namespace=None, data=None):
    """Plugin entry point.

    Args:
        context (:class:`pyblish.api.Context`): Context.
        name (str, optional): Container name.
        namespace (str, optional): Container namespace.
        data (dict, optional): Additional data passed into loader.

    """
    fname = Path(self.filepath_from_context(context))
    self_name = self.__class__.__name__
    collections, remainder = clique.assemble(
        os.listdir(fname.parent.as_posix())
    )
    files = []
    if collections:
        for f in list(collections[0]):
            files.append(fname.parent.joinpath(f).as_posix())
    else:
        files.append(fname.parent.joinpath(remainder[0]).as_posix())

    folder_name = context["folder"]["name"]
    product_name = context["product"]["name"]

    group_id = str(uuid.uuid4())
    read_node = harmony.send(
        {
            "function": f"AyonHarmony.Loaders.{self_name}.importFiles",  # noqa: E501
            "args": [
                files,
                folder_name,
                product_name,
                1,
                group_id
            ]
        }
    )["result"]

    return harmony.containerise(
        f"{folder_name}_{product_name}",
        namespace,
        read_node,
        context,
        self_name,
        nodes=[read_node]
    )

remove(container)

Remove loaded container.

Parameters:

Name Type Description Default
container dict

Container data.

required
Source code in client/ayon_harmony/plugins/load/load_imagesequence.py
139
140
141
142
143
144
145
146
147
148
149
150
def remove(self, container):
    """Remove loaded container.

    Args:
        container (dict): Container data.

    """
    node = container.get("nodes").pop()
    harmony.send(
        {"function": "AyonHarmony.deleteNode", "args": [node]}
    )
    harmony.imprint(node, {}, remove=True)

switch(container, context)

Switch loaded representations.

Source code in client/ayon_harmony/plugins/load/load_imagesequence.py
152
153
154
def switch(self, container, context):
    """Switch loaded representations."""
    self.update(container, context)

update(container, context)

Update loaded containers.

Parameters:

Name Type Description Default
container dict

Container data.

required
context dict

Representation context data.

required
Source code in client/ayon_harmony/plugins/load/load_imagesequence.py
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
def update(self, container, context):
    """Update loaded containers.

    Args:
        container (dict): Container data.
        context (dict): Representation context data.

    """
    self_name = self.__class__.__name__
    node = container.get("nodes").pop()

    repre_entity = context["representation"]
    path = get_representation_path(repre_entity)
    collections, remainder = clique.assemble(
        os.listdir(os.path.dirname(path))
    )
    files = []
    if collections:
        for f in list(collections[0]):
            files.append(
                os.path.join(
                    os.path.dirname(path), f
                ).replace("\\", "/")
            )
    else:
        files.append(
            os.path.join(
                os.path.dirname(path), remainder[0]
            ).replace("\\", "/")
        )

    harmony.send(
        {
            "function": f"AyonHarmony.Loaders.{self_name}.replaceFiles",
            "args": [files, node, 1]
        }
    )

    # Colour node.
    if is_representation_from_latest(repre_entity):
        harmony.send(
            {
                "function": "AyonHarmony.setColor",
                "args": [node, [0, 255, 0, 255]]
            })
    else:
        harmony.send(
            {
                "function": "AyonHarmony.setColor",
                "args": [node, [255, 0, 0, 255]]
            })

    harmony.imprint(
        node, {"representation": repre_entity["id"]}
    )