Skip to content

load_image_from_sequence

ImageFromSequenceLoader

Bases: PhotoshopLoader

Load specific image from sequence

Used only as quick load of reference file from a sequence.

Plain ImageLoader picks first frame from sequence.

Loads only existing files - currently not possible to limit loaders to single select - multiselect. If user selects multiple repres, list for all of them is provided, but selection is only single file. This loader will be triggered multiple times, but selected name will match only to proper path.

Loader doesn't do containerization as there is currently no data model of 'frame of rendered files' (only rendered sequence), update would be difficult.

Source code in client/ayon_photoshop/plugins/load/load_image_from_sequence.py
 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
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
class ImageFromSequenceLoader(photoshop.PhotoshopLoader):
    """ Load specific image from sequence

        Used only as quick load of reference file from a sequence.

        Plain ImageLoader picks first frame from sequence.

        Loads only existing files - currently not possible to limit loaders
        to single select - multiselect. If user selects multiple repres, list
        for all of them is provided, but selection is only single file.
        This loader will be triggered multiple times, but selected name will
        match only to proper path.

        Loader doesn't do containerization as there is currently no data model
        of 'frame of rendered files' (only rendered sequence), update would be
        difficult.
    """

    product_types = {"render"}
    representations = {"*"}
    options = []

    def load(self, context, name=None, namespace=None, data=None):

        path = self.filepath_from_context(context)
        if data.get("frame"):
            path = os.path.join(
                os.path.dirname(path), data["frame"]
            )
            if not os.path.exists(path):
                return

        stub = self.get_stub()
        layer_name = get_unique_layer_name(
            stub.get_layers(), context["folder"]["name"], name
        )

        with photoshop.maintained_selection():
            layer = stub.import_smart_object(path, layer_name)

        self[:] = [layer]
        namespace = namespace or layer_name

        return namespace

    @classmethod
    def get_options(cls, repre_contexts):
        """
            Returns list of files for selected 'repre_contexts'.

            It returns only files with same extension as in context as it is
            expected that context points to sequence of frames.

            Returns:
                (list) of qargparse.Choice
        """
        files = []
        for context in repre_contexts:
            fname = cls.filepath_from_context(context)
            _, file_extension = os.path.splitext(fname)

            for file_name in os.listdir(os.path.dirname(fname)):
                if not file_name.endswith(file_extension):
                    continue
                files.append(file_name)

        # return selection only if there is something
        if not files or len(files) <= 1:
            return []

        return [
            qargparse.Choice(
                "frame",
                label="Select specific file",
                items=files,
                default=0,
                help="Which frame should be loaded?"
            )
        ]

    def update(self, container, context):
        """No update possible, not containerized."""
        pass

    def remove(self, container):
        """No update possible, not containerized."""
        pass

get_options(repre_contexts) classmethod

Returns list of files for selected 'repre_contexts'.

It returns only files with same extension as in context as it is expected that context points to sequence of frames.

Returns:

Type Description

(list) of qargparse.Choice

Source code in client/ayon_photoshop/plugins/load/load_image_from_sequence.py
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
@classmethod
def get_options(cls, repre_contexts):
    """
        Returns list of files for selected 'repre_contexts'.

        It returns only files with same extension as in context as it is
        expected that context points to sequence of frames.

        Returns:
            (list) of qargparse.Choice
    """
    files = []
    for context in repre_contexts:
        fname = cls.filepath_from_context(context)
        _, file_extension = os.path.splitext(fname)

        for file_name in os.listdir(os.path.dirname(fname)):
            if not file_name.endswith(file_extension):
                continue
            files.append(file_name)

    # return selection only if there is something
    if not files or len(files) <= 1:
        return []

    return [
        qargparse.Choice(
            "frame",
            label="Select specific file",
            items=files,
            default=0,
            help="Which frame should be loaded?"
        )
    ]

remove(container)

No update possible, not containerized.

Source code in client/ayon_photoshop/plugins/load/load_image_from_sequence.py
93
94
95
def remove(self, container):
    """No update possible, not containerized."""
    pass

update(container, context)

No update possible, not containerized.

Source code in client/ayon_photoshop/plugins/load/load_image_from_sequence.py
89
90
91
def update(self, container, context):
    """No update possible, not containerized."""
    pass