Skip to content

load_image

ImportImage

Bases: Loader

Load image or image sequence to TVPaint as new layer.

Source code in client/ayon_tvpaint/plugins/load/load_image.py
 6
 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
class ImportImage(plugin.Loader):
    """Load image or image sequence to TVPaint as new layer."""

    product_types = {"render", "image", "background", "plate", "review"}
    representations = {"*"}
    settings_category = "tvpaint"

    label = "Import Image"
    order = 1
    icon = "image"
    color = "white"

    import_script = (
        "filepath = \"{}\"\n"
        "layer_name = \"{}\"\n"
        "tv_loadsequence filepath {}PARSE layer_id\n"
        "tv_layerrename layer_id layer_name"
    )

    defaults = {
        "stretch": True,
        "timestretch": True,
        "preload": True
    }

    @classmethod
    def get_options(cls, contexts):
        return [
            BoolDef(
                "stretch",
                label="Stretch to project size",
                default=cls.defaults["stretch"],
                tooltip="Stretch loaded image/s to project resolution?"
            ),
            BoolDef(
                "timestretch",
                label="Stretch to timeline length",
                default=cls.defaults["timestretch"],
                tooltip="Clip loaded image/s to timeline length?"
            ),
            BoolDef(
                "preload",
                label="Preload loaded image/s",
                default=cls.defaults["preload"],
                tooltip="Preload image/s?"
            )
        ]

    def load(self, context, name, namespace, options):
        stretch = options.get("stretch", self.defaults["stretch"])
        timestretch = options.get("timestretch", self.defaults["timestretch"])
        preload = options.get("preload", self.defaults["preload"])

        load_options = []
        if stretch:
            load_options.append("\"STRETCH\"")
        if timestretch:
            load_options.append("\"TIMESTRETCH\"")
        if preload:
            load_options.append("\"PRELOAD\"")

        load_options_str = ""
        for load_option in load_options:
            load_options_str += (load_option + " ")

        # Prepare layer name
        folder_name = context["folder"]["name"]
        version_name = context["version"]["name"]
        layer_name = "{}_{}_v{:0>3}".format(
            folder_name,
            name,
            version_name
        )
        # Fill import script with filename and layer name
        # - filename mus not contain backwards slashes
        path = self.filepath_from_context(context).replace("\\", "/")
        george_script = self.import_script.format(
            path,
            layer_name,
            load_options_str
        )
        return execute_george_through_file(george_script)