From 322ec3e3c8801aff3edf0ec05e153fbc7b457bb1 Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Thu, 11 Jul 2019 16:53:42 +0200 Subject: [PATCH] fix(nuke): plublish workfile handle_start/end was not correct --- pype/plugins/global/publish/integrate_new.py | 3 +- pype/plugins/nuke/load/load_script_precomp.py | 6 +- .../nuke/publish/collect_current_file.py | 3 +- pype/plugins/nuke/publish/collect_workfile.py | 56 ++++++++++++++----- pype/plugins/nuke/publish/validate_script.py | 30 +++++----- 5 files changed, 66 insertions(+), 32 deletions(-) diff --git a/pype/plugins/global/publish/integrate_new.py b/pype/plugins/global/publish/integrate_new.py index ec0cca10d6..e70657eef9 100644 --- a/pype/plugins/global/publish/integrate_new.py +++ b/pype/plugins/global/publish/integrate_new.py @@ -539,7 +539,8 @@ class IntegrateAssetNew(pyblish.api.InstancePlugin): # Include optional data if present in optionals = [ - "startFrame", "endFrame", "step", "handles", "sourceHashes" + "startFrame", "endFrame", "step", "handles", + "handle_end", "handle_start", "sourceHashes" ] for key in optionals: if key in instance.data: diff --git a/pype/plugins/nuke/load/load_script_precomp.py b/pype/plugins/nuke/load/load_script_precomp.py index 6fd76edd03..bc63150206 100644 --- a/pype/plugins/nuke/load/load_script_precomp.py +++ b/pype/plugins/nuke/load/load_script_precomp.py @@ -39,12 +39,14 @@ class LinkAsGroup(api.Loader): precomp_name = context["representation"]["context"]["subset"] + self.log.info("versionData: {}\n".format(context["version"]["data"])) + # Set global in point to start frame (if in version.data) start = context["version"]["data"].get("startFrame", None) + self.log.info("start: {}\n".format(start)) # add additional metadata from the version to imprint to Avalon knob - add_keys = ["startFrame", "endFrame", "handles", - "source", "author", "fps"] + add_keys = ["startFrame", "endFrame", "handle_start", "handle_end", "source", "author", "fps"] data_imprint = { "start_frame": start, diff --git a/pype/plugins/nuke/publish/collect_current_file.py b/pype/plugins/nuke/publish/collect_current_file.py index 35a0ef4c2a..253b9a7a24 100644 --- a/pype/plugins/nuke/publish/collect_current_file.py +++ b/pype/plugins/nuke/publish/collect_current_file.py @@ -1,10 +1,11 @@ import pyblish.api -class SelectCurrentFile(pyblish.api.ContextPlugin): +class CollectCurrentFile(pyblish.api.ContextPlugin): """Inject the current working file into context""" order = pyblish.api.CollectorOrder - 0.5 + label = "Collect Current File" hosts = ["nuke"] def process(self, context): diff --git a/pype/plugins/nuke/publish/collect_workfile.py b/pype/plugins/nuke/publish/collect_workfile.py index dc8472e4c2..2ec6464ace 100644 --- a/pype/plugins/nuke/publish/collect_workfile.py +++ b/pype/plugins/nuke/publish/collect_workfile.py @@ -2,6 +2,8 @@ import nuke import pyblish.api import os +import pype.api as pype + from avalon.nuke import ( get_avalon_knob_data, add_publish_knob @@ -24,16 +26,20 @@ class CollectWorkfile(pyblish.api.ContextPlugin): family = "workfile" # creating instances per write node - file_path = root['name'].value() + file_path = context.data["currentFile"] + staging_dir = os.path.dirname(file_path) base_name = os.path.basename(file_path) subset = "{0}_{1}".format(os.getenv("AVALON_TASK", None), family) + # get version string + version = pype.get_version_from_path(base_name) + # Get frame range first_frame = int(root["first_frame"].getValue()) last_frame = int(root["last_frame"].getValue()) - handle_start = int(knob_data["handle_start"]) - handle_end = int(knob_data["handle_end"]) + handle_start = int(knob_data.get("handle_start", 0)) + handle_end = int(knob_data.get("handle_end", 0)) # Get format format = root['format'].value() @@ -45,23 +51,47 @@ class CollectWorkfile(pyblish.api.ContextPlugin): instance = context.create_instance(subset) instance.add(root) - instance.data.update({ - "subset": subset, + script_data = { "asset": os.getenv("AVALON_ASSET", None), - "label": base_name, - "name": base_name, - "startFrame": first_frame, - "endFrame": last_frame, + "version": version, + "startFrame": first_frame + handle_start, + "endFrame": last_frame - handle_end, "resolution_width": resolution_width, "resolution_height": resolution_height, "pixel_aspect": pixel_aspect, - "publish": root.knob('publish').value(), - "family": family, - "representation": "nk", + + # backward compatibility + "handles": handle_start, + "handle_start": handle_start, "handle_end": handle_end, "step": 1, - "fps": int(root['fps'].value()), + "fps": root['fps'].value(), + } + context.data.update(script_data) + + # creating instance data + instance.data.update({ + "subset": subset, + "label": base_name, + "name": base_name, + "publish": root.knob('publish').value(), + "family": family, + "representations": list() }) + + # adding basic script data + instance.data.update(script_data) + + # creating representation + representation = { + 'name': 'nk', + 'ext': 'nk', + 'files': base_name, + "stagingDir": staging_dir, + } + + instance.data["representations"].append(representation) + self.log.info('Publishing script version') context.data["instances"].append(instance) diff --git a/pype/plugins/nuke/publish/validate_script.py b/pype/plugins/nuke/publish/validate_script.py index f79d4ab862..4ad76b898b 100644 --- a/pype/plugins/nuke/publish/validate_script.py +++ b/pype/plugins/nuke/publish/validate_script.py @@ -12,8 +12,8 @@ class ValidateScript(pyblish.api.InstancePlugin): hosts = ["nuke"] def process(self, instance): - instance_data = instance.data - asset_name = instance_data["asset"] + ctx_data = instance.context.data + asset_name = ctx_data["asset"] asset = io.find_one({ "type": "asset", @@ -66,19 +66,19 @@ class ValidateScript(pyblish.api.InstancePlugin): handle_end = asset_attributes["handle_end"] # Set frame range with handles - asset_attributes["fstart"] -= handle_start - asset_attributes["fend"] += handle_end + # asset_attributes["fstart"] -= handle_start + # asset_attributes["fend"] += handle_end # Get values from nukescript script_attributes = { - "handle_start": instance_data["handle_start"], - "handle_end": instance_data["handle_end"], - "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"] + "handle_start": ctx_data["handle_start"], + "handle_end": ctx_data["handle_end"], + "fps": ctx_data["fps"], + "fstart": ctx_data["startFrame"], + "fend": ctx_data["endFrame"], + "resolution_width": ctx_data["resolution_width"], + "resolution_height": ctx_data["resolution_height"], + "pixel_aspect": ctx_data["pixel_aspect"] } # Compare asset's values Nukescript X Database @@ -95,10 +95,10 @@ class ValidateScript(pyblish.api.InstancePlugin): # 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) + ((handle_start > 0) or (handle_end > 0)) ): - handles = str(handles).replace(".0", "") - msg += " (handles are set to {})".format(handles) + msg += " (`handle_start` are set to {})".format(handle_start) + msg += " (`handle_end` are set to {})".format(handle_end) message = msg.format(", ".join(not_matching)) raise ValueError(message)