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
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",
            })["result"]

        # skip collecting if not in allowed task
        if self.allowed_tasks:
            task_name = context.data["anatomyData"]["task"]["name"].lower()
            if (not any([re.search(pattern, task_name)
                         for pattern in self.allowed_tasks])):
                return
        folder_path = context.data["folderPath"]

        product_type = "harmony.palette"
        for name, id in palettes.items():
            instance = context.create_instance(name)
            instance.data.update({
                "id": id,
                "productType": product_type,
                "family": product_type,
                "families": [product_type],
                "folderPath": folder_path,
                "productName": "{}{}".format("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
def process(self, context):
    """Collector entry point."""
    self_name = self.__class__.__name__
    palettes = harmony.send(
        {
            "function": f"AyonHarmony.Publish.{self_name}.getPalettes",
        })["result"]

    # skip collecting if not in allowed task
    if self.allowed_tasks:
        task_name = context.data["anatomyData"]["task"]["name"].lower()
        if (not any([re.search(pattern, task_name)
                     for pattern in self.allowed_tasks])):
            return
    folder_path = context.data["folderPath"]

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