Skip to content

validate_render_layer_group

ValidateRenderLayerGroups

Bases: ContextPlugin

Validate group ids of renderLayer products.

Validate that there are not 2 render layers using the same group.

Source code in client/ayon_tvpaint/plugins/publish/validate_render_layer_group.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
class ValidateRenderLayerGroups(pyblish.api.ContextPlugin):
    """Validate group ids of renderLayer products.

    Validate that there are not 2 render layers using the same group.
    """

    label = "Validate Render Layers Group"
    order = pyblish.api.ValidatorOrder + 0.1

    settings_category = "tvpaint"

    def process(self, context):
        # Prepare layers
        render_layers_by_group_id = collections.defaultdict(list)
        for instance in context:
            families = instance.data.get("families")
            if not families or "renderLayer" not in families:
                continue

            group_id = instance.data["creator_attributes"]["group_id"]
            render_layers_by_group_id[group_id].append(instance)

        duplicated_instances = []
        for group_id, instances in render_layers_by_group_id.items():
            if len(instances) > 1:
                duplicated_instances.append((group_id, instances))

        if not duplicated_instances:
            return

        # Exception message preparations
        groups_data = context.data["groupsData"]
        groups_by_id = {
            group["group_id"]: group
            for group in groups_data
        }

        per_group_msgs = []
        groups_information_lines = []
        for group_id, instances in duplicated_instances:
            group = groups_by_id[group_id]
            group_label = "Group \"{}\" ({})".format(
                group["name"],
                group["group_id"],
            )
            line_join_product_names = "\n".join([
                f"    - {instance['productName']}"
                for instance in instances
            ])
            joined_product_names = ", ".join([
                f"\"{instance['productName']}\""
                for instance in instances
            ])
            per_group_msgs.append(
                "{} < {} >".format(group_label, joined_product_names)
            )
            groups_information_lines.append(
                "<b>{}</b>\n{}".format(
                    group_label, line_join_product_names
                )
            )

        # Raise an error
        raise PublishXmlValidationError(
            self,
            (
                "More than one Render Layer is using the same TVPaint"
                " group color. {}"
            ).format(" | ".join(per_group_msgs)),
            formatting_data={
                "groups_information": "\n".join(groups_information_lines)
            }
        )