Skip to content

validate_scene_settings

Validate scene settings. Requires: instance -> folderEntity instance -> anatomyData

ValidateSceneSettings

Bases: OptionalPyblishPluginMixin, InstancePlugin

Ensures that Composition Settings (right mouse on comp) are same as task or folder attributes in AYON.

By default checks only duration - how many frames should be rendered. Compares: Frame start - Frame end + 1 against duration in Composition Settings.

If this complains

Check error message where is discrepancy. Check/modify rendered Composition Settings.

If you know what you are doing run publishing again, uncheck this validation before Validation phase.

Source code in client/ayon_aftereffects/plugins/publish/validate_scene_settings.py
 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
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
class ValidateSceneSettings(OptionalPyblishPluginMixin,
                            pyblish.api.InstancePlugin):
    """Ensures that Composition Settings (right mouse on comp) are same as
    task or folder attributes in AYON.

    By default checks only duration - how many frames should be rendered.
    Compares:
        Frame start - Frame end + 1 against duration in Composition Settings.

    If this complains:
        Check error message where is discrepancy.
        Check/modify rendered Composition Settings.

    If you know what you are doing run publishing again, uncheck this
    validation before Validation phase.
    """

    """
        Dev docu:
        Could be configured by 'presets/plugins/aftereffects/publish'

        skip_timelines_check - fill task name for which skip validation of
            frameStart
            frameEnd
            fps
            handleStart
            handleEnd
        skip_resolution_check - fill entity type ('folder') to skip validation
            resolutionWidth
            resolutionHeight
            TODO support in extension is missing for now

         By defaults validates duration (how many frames should be published)
    """

    order = pyblish.api.ValidatorOrder
    label = "Validate Scene Settings"
    families = ["render.farm", "render.local", "render"]
    hosts = ["aftereffects"]
    settings_category = "aftereffects"
    optional = True

    skip_timelines_check = [".*"]  # * >> skip for all
    skip_resolution_check = [".*"]

    def process(self, instance):
        # Skip the instance if is not active by data on the instance
        if not self.is_active(instance.data):
            return

        entity: dict = (
            instance.data.get("taskEntity")
            or instance.data["folderEntity"]
        )
        expected_settings = get_entity_attributes(entity)
        self.log.debug(f"Found entity attributes: {expected_settings}")

        task_name: str = instance.data["task"]
        if any(re.search(pattern, task_name)
                for pattern in self.skip_resolution_check):
            self.log.debug(
                f"Skipping resolution check for task name: {task_name}"
            )
            expected_settings.pop("resolutionWidth")
            expected_settings.pop("resolutionHeight")

        if any(re.search(pattern, task_name)
                for pattern in self.skip_timelines_check):
            self.log.debug(
                f"Skipping frames check for task name: {task_name}"
            )
            expected_settings.pop('fps', None)
            expected_settings.pop('frameStart', None)
            expected_settings.pop('frameEnd', None)
            expected_settings.pop('handleStart', None)
            expected_settings.pop('handleEnd', None)

        # handle case where ftrack uses only two decimal places
        # 23.976023976023978 vs. 23.98
        fps = instance.data.get("fps")
        if fps:
            if isinstance(fps, float):
                fps = float(
                    "{:.2f}".format(fps))
            expected_settings["fps"] = fps

        duration = (
            instance.data.get("frameEndHandle")
            - instance.data.get("frameStartHandle")
            + 1
        )

        self.log.debug(f"Validating attributes: {expected_settings}")

        current_settings = {
            "fps": fps,
            "frameStart": instance.data.get("frameStart"),
            "frameEnd": instance.data.get("frameEnd"),
            "handleStart": instance.data.get("handleStart"),
            "handleEnd": instance.data.get("handleEnd"),
            "frameStartHandle": instance.data.get("frameStartHandle"),
            "frameEndHandle": instance.data.get("frameEndHandle"),
            "resolutionWidth": instance.data.get("resolutionWidth"),
            "resolutionHeight": instance.data.get("resolutionHeight"),
            "duration": duration
        }
        self.log.debug(f"Comp attributes: {current_settings}")

        invalid_settings = []
        invalid_keys = set()
        for key, value in expected_settings.items():
            if value != current_settings[key]:
                msg = "'{}' expected: '{}'  found: '{}'".format(
                    key, value, current_settings[key])

                if key == "duration" and expected_settings.get("handleStart"):
                    msg += (
                        "Handles included in calculation. Remove "
                        "handles in DB or extend frame range in "
                        "Composition Setting."
                    )

                invalid_settings.append(msg)
                invalid_keys.add(key)

        if invalid_settings:
            msg = "Found invalid settings:\n{}".format(
                "\n".join(invalid_settings)
            )

            invalid_keys_str = ",".join(invalid_keys)
            break_str = "<br/>"
            invalid_setting_str = "<b>Found invalid settings:</b><br/>{}".\
                format(break_str.join(invalid_settings))

            formatting_data = {
                "invalid_setting_str": invalid_setting_str,
                "invalid_keys_str": invalid_keys_str
            }
            raise PublishXmlValidationError(self, msg,
                                            formatting_data=formatting_data)

        if not os.path.exists(instance.data.get("source")):
            scene_url = instance.data.get("source")
            msg = "Scene file {} not found (saved under wrong name)".format(
                scene_url
            )
            formatting_data = {
                "scene_url": scene_url
            }
            raise PublishXmlValidationError(self, msg, key="file_not_found",
                                            formatting_data=formatting_data)