Skip to content

validate_collected_trackItem

ValidateCollectedTrackItem

Bases: InstancePlugin

Validate the collected timeline clip.

Source code in client/ayon_hiero/plugins/publish/validate_collected_trackItem.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
74
class ValidateCollectedTrackItem(
    pyblish.api.InstancePlugin
):
    """Validate the collected timeline clip."""

    order = ValidateContentsOrder
    hosts = ["hiero"]
    families = ["shot", "audio", "plate", "take"]
    label = "Validate Collected Timeline Clip"
    actions = [RepairAction]

    def process(self, instance):
        if instance.data["trackItem"] is None:
            raise PublishValidationError(
                "Referenced product item is not linked to the correct clip. "
                "This might be because the timeline clip was copied/pasted from another sequence. \n"
                "Use 'Repair' to relink the source clip to this instance."
            )

    @classmethod
    def is_associated_item(
        cls,
        instance,
        track_item,
    ) -> bool:
        """
        """
        item_tag = lib.get_trackitem_ayon_tag(track_item)
        if not item_tag:
            return False

        tag_data = tags.get_tag_data(item_tag) or {}
        if "hiero_sub_products" not in tag_data:
            return False

        for value in tag_data.get("hiero_sub_products", {}).values():
            if (
                value.get("productBaseType") == instance.data["productBaseType"]
                and value.get("folderPath") == instance.data["folderPath"]
                and value.get("variant") == instance.data["variant"]
            ):
                track_item_index = track_item.guid()
                value["clip_index"] = track_item_index
                tag_data["clip_index"] = track_item_index
                instance.data["clip_index"] = track_item_index
                tags.update_tag(item_tag, {"metadata": tag_data})
                return True

        return False

    @classmethod
    def repair(cls, instance):
        """Attempt to relink the clip to the instance."""
        active_timeline = instance.context.data["activeTimeline"]
        for video_track in active_timeline.videoTracks():
            for item in video_track.items():
                if cls.is_associated_item(instance, item):
                    instance.data["clip_index"] = item.guid()
                    return

        raise PublishValidationError(
            "Could not find track item associated "
            "to this instance in the active timeline."
        )

is_associated_item(instance, track_item) classmethod

Source code in client/ayon_hiero/plugins/publish/validate_collected_trackItem.py
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
@classmethod
def is_associated_item(
    cls,
    instance,
    track_item,
) -> bool:
    """
    """
    item_tag = lib.get_trackitem_ayon_tag(track_item)
    if not item_tag:
        return False

    tag_data = tags.get_tag_data(item_tag) or {}
    if "hiero_sub_products" not in tag_data:
        return False

    for value in tag_data.get("hiero_sub_products", {}).values():
        if (
            value.get("productBaseType") == instance.data["productBaseType"]
            and value.get("folderPath") == instance.data["folderPath"]
            and value.get("variant") == instance.data["variant"]
        ):
            track_item_index = track_item.guid()
            value["clip_index"] = track_item_index
            tag_data["clip_index"] = track_item_index
            instance.data["clip_index"] = track_item_index
            tags.update_tag(item_tag, {"metadata": tag_data})
            return True

    return False

repair(instance) classmethod

Attempt to relink the clip to the instance.

Source code in client/ayon_hiero/plugins/publish/validate_collected_trackItem.py
61
62
63
64
65
66
67
68
69
70
71
72
73
74
@classmethod
def repair(cls, instance):
    """Attempt to relink the clip to the instance."""
    active_timeline = instance.context.data["activeTimeline"]
    for video_track in active_timeline.videoTracks():
        for item in video_track.items():
            if cls.is_associated_item(instance, item):
                instance.data["clip_index"] = item.guid()
                return

    raise PublishValidationError(
        "Could not find track item associated "
        "to this instance in the active timeline."
    )