Skip to content

load_palette

ImportPaletteLoader

Bases: LoaderPlugin

Import palettes.

Source code in client/ayon_harmony/plugins/load/load_palette.py
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
class ImportPaletteLoader(load.LoaderPlugin):
    """Import palettes."""

    product_types = {"palette", "harmony.palette"}
    representations = {"plt"}
    label = "Import Palette"

    def load(self, context, name=None, namespace=None, data=None):
        name = self.load_palette(context["representation"])

        return harmony.containerise(
            name,
            namespace,
            name,
            context,
            self.__class__.__name__
        )

    def load_palette(self, context):
        product_name = context["product"]["name"]
        repre_entity = context["representation"]
        name = product_name.replace("palette", "")

        # Overwrite palette on disk.
        scene_path = harmony.send(
            {"function": "scene.currentProjectPath"}
        )["result"]
        src = get_representation_path(repre_entity)
        dst = os.path.join(
            scene_path,
            "palette-library",
            "{}.plt".format(name)
        )
        shutil.copy(src, dst)

        harmony.save_scene()

        msg = "Updated {}.".format(product_name)
        msg += " You need to reload the scene to see the changes.\n"
        msg += "Please save workfile when ready and use Workfiles "
        msg += "to reopen it."

        harmony.send(
            {
                "function": "AyonHarmony.message",
                "args": msg
            })
        return name

    def remove(self, container):
        harmony.remove(container["name"])

    def switch(self, container, context):
        self.update(container, context)

    def update(self, container, context):
        self.remove(container)
        name = self.load_palette(context)

        repre_entity = context["representation"]
        container["representation"] = repre_entity["id"]
        container["name"] = name
        harmony.imprint(name, container)