Skip to content

collect_palettes

Collect palettes from Harmony.

CollectPalettes

Bases: ContextPlugin

Gather palettes from scene when publishing templates.

Source code in client/ayon_harmony/plugins/publish/collect_palettes.py
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
class CollectPalettes(pyblish.api.ContextPlugin):
    """Gather palettes from scene when publishing templates."""

    label = "Palettes"
    order = pyblish.api.CollectorOrder + 0.003
    hosts = ["harmony"]

    settings_category = "harmony"

    # list of regexes for task names where collecting should happen
    allowed_tasks = []

    def process(self, context):
        """Collector entry point."""
        self_name = self.__class__.__name__
        palettes = harmony.send(
            {
                "function": f"AyonHarmony.Publish.{self_name}.getPalettes",
                "args": True,
            })["result"]

        # skip collecting if not in allowed task
        if self.allowed_tasks:
            task_name = context.data["task"].lower()
            if not any(
                re.search(pattern, task_name)
                for pattern in self.allowed_tasks
            ):
                self.log.info(
                    "Skipping collecting palettes, task is not in"
                    f" allowed tasks: {self.allowed_tasks}"
                )
                return

        folder_path = context.data["folderPath"]

        product_type = "harmony.palette"
        for name, palette_id in palettes.items():
            instance = context.create_instance(name)
            instance.data.update({
                "id": palette_id,
                "productType": product_type,
                "family": product_type,
                "families": [product_type],
                "folderPath": folder_path,
                # TODO use product name template to calculate product name
                "productName": f"palette{name}"
            })
            self.log.info(
                "Created instance:\n" + json.dumps(
                    instance.data, sort_keys=True, indent=4
                )
            )

process(context)

Collector entry point.

Source code in client/ayon_harmony/plugins/publish/collect_palettes.py
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
def process(self, context):
    """Collector entry point."""
    self_name = self.__class__.__name__
    palettes = harmony.send(
        {
            "function": f"AyonHarmony.Publish.{self_name}.getPalettes",
            "args": True,
        })["result"]

    # skip collecting if not in allowed task
    if self.allowed_tasks:
        task_name = context.data["task"].lower()
        if not any(
            re.search(pattern, task_name)
            for pattern in self.allowed_tasks
        ):
            self.log.info(
                "Skipping collecting palettes, task is not in"
                f" allowed tasks: {self.allowed_tasks}"
            )
            return

    folder_path = context.data["folderPath"]

    product_type = "harmony.palette"
    for name, palette_id in palettes.items():
        instance = context.create_instance(name)
        instance.data.update({
            "id": palette_id,
            "productType": product_type,
            "family": product_type,
            "families": [product_type],
            "folderPath": folder_path,
            # TODO use product name template to calculate product name
            "productName": f"palette{name}"
        })
        self.log.info(
            "Created instance:\n" + json.dumps(
                instance.data, sort_keys=True, indent=4
            )
        )