From 7dbc0376f641b6dfbd66d62e80e0b52ab5eddb27 Mon Sep 17 00:00:00 2001 From: Jakub Trllo Date: Fri, 4 Jan 2019 16:28:26 +0100 Subject: [PATCH] - script is validated. - added format in collect script plugin --- pype/plugins/nuke/publish/collect_script.py | 9 ++ pype/plugins/nuke/publish/validate_script.py | 106 +++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 pype/plugins/nuke/publish/validate_script.py diff --git a/pype/plugins/nuke/publish/collect_script.py b/pype/plugins/nuke/publish/collect_script.py index 92557b2665..f0c917b449 100644 --- a/pype/plugins/nuke/publish/collect_script.py +++ b/pype/plugins/nuke/publish/collect_script.py @@ -34,6 +34,12 @@ class CollectScript(pyblish.api.ContextPlugin): first_frame = int(root["first_frame"].getValue()) last_frame = int(root["last_frame"].getValue()) + # Get format + format = root['format'].value() + resolution_width = format.width() + resolution_height = format.height() + pixel_aspect = format.pixelAspect() + # Create instance instance = context.create_instance(subset) instance.add(root) @@ -45,6 +51,9 @@ class CollectScript(pyblish.api.ContextPlugin): "name": base_name, "startFrame": first_frame, "endFrame": last_frame, + "resolution_width": resolution_width, + "resolution_height": resolution_height, + "pixel_aspect": pixel_aspect, "publish": root.knob('publish').value(), "family": family, "representation": "nk", diff --git a/pype/plugins/nuke/publish/validate_script.py b/pype/plugins/nuke/publish/validate_script.py new file mode 100644 index 0000000000..a4ec60d96d --- /dev/null +++ b/pype/plugins/nuke/publish/validate_script.py @@ -0,0 +1,106 @@ +import pyblish.api +from avalon import io + + +@pyblish.api.log +class ValidateScript(pyblish.api.InstancePlugin): + """ Validates file output. """ + + order = pyblish.api.ValidatorOrder + 0.1 + families = ["nukescript"] + label = "Check nukescript settings" + hosts = ["nuke"] + + def process(self, instance): + instance_data = instance.data + asset_name = instance_data["asset"] + + asset = io.find_one({ + "type": "asset", + "name": asset_name + }) + asset_data = asset["data"] + + # These attributes will be checked + attributes = [ + "fps", "fstart", "fend", + "resolution_width", "resolution_height", "pixel_aspect" + ] + + # Value of these attributes can be found on parents + hierarchical_attributes = ["fps"] + + missing_attributes = [] + asset_attributes = {} + for attr in attributes: + if attr in asset_data: + asset_attributes[attr] = asset_data[attr] + + elif attr in hierarchical_attributes: + # Try to find fps on parent + parent = asset['parent'] + if asset_data['visualParent'] is not None: + parent = asset_data['visualParent'] + + value = self.check_parent_hierarchical(parent, attr) + if value is None: + missing_attributes.append(attr) + else: + asset_attributes[attr] = value + + else: + missing_attributes.append(attr) + + # Raise error if attributes weren't found on asset in database + if len(missing_attributes) > 0: + atr = ", ".join(missing_attributes) + msg = 'Missing attributes "{}" in asset "{}"' + message = msg.format(atr, asset_name) + raise ValueError(message) + + # Get handles from database, Default is 0 (if not found) + handles = 0 + if "handles" in asset_data: + handles = asset_data["handles"] + + # Set frame range with handles + asset_attributes["fstart"] -= handles + asset_attributes["fend"] += handles + + # Get values from nukescript + script_attributes = { + "fps": instance_data["fps"], + "fstart": instance_data["startFrame"], + "fend": instance_data["endFrame"], + "resolution_width": instance_data["resolution_width"], + "resolution_height": instance_data["resolution_height"], + "pixel_aspect": instance_data["pixel_aspect"] + } + + # Compare asset's values Nukescript X Database + not_matching = [] + for attr in attributes: + if asset_attributes[attr] != script_attributes[attr]: + not_matching.append(attr) + + # Raise error if not matching + if len(not_matching) > 0: + msg = "Attributes '{}' aro not set correctly" + # Alert user that handles are set if Frame start/end not match + if ( + (("fstart" in not_matching) or ("fend" in not_matching)) and + (handles > 0) + ): + handles = str(handles).replace(".0", "") + msg += " (handles are set to {})".format(handles) + message = msg.format(", ".join(not_matching)) + raise ValueError(message) + + def check_parent_hierarchical(self, entityId, attr): + if entityId is None: + return None + entity = io.find_one({"_id": entityId}) + if attr in entity['data']: + return entity['data'][attr] + else: + return self.check_parent_hierarchical(entity['parent'], attr)