Nuke: rewrite collect workfile so we are able to disable its publishing

This commit is contained in:
Jakub Jezek 2022-10-27 11:20:21 +02:00
parent b6c6fad10e
commit 8a2c10e3d1
No known key found for this signature in database
GPG key ID: 730D7C02726179A7
2 changed files with 72 additions and 48 deletions

View file

@ -0,0 +1,69 @@
import os
import nuke
import pyblish.api
import openpype.api as api
import openpype.hosts.nuke.api as napi
from openpype.pipeline import KnownPublishError
class CollectContextData(pyblish.api.ContextPlugin):
"""Collect current context publish."""
order = pyblish.api.CollectorOrder - 0.499
label = "Collect context data"
hosts = ['nuke']
def process(self, context): # sourcery skip: avoid-builtin-shadow
root_node = nuke.root()
current_file = os.path.normpath(root_node.name())
if current_file.lower() == "root":
raise KnownPublishError(
"Workfile is not correct file name. \n"
"Use workfile tool to manage the name correctly."
)
# Get frame range
first_frame = int(root_node["first_frame"].getValue())
last_frame = int(root_node["last_frame"].getValue())
# get instance data from root
root_instance_context = napi.get_node_data(
root_node, napi.INSTANCE_DATA_KNOB
)
handle_start = root_instance_context["handleStart"]
handle_end = root_instance_context["handleEnd"]
# Get format
format = root_node['format'].value()
resolution_width = format.width()
resolution_height = format.height()
pixel_aspect = format.pixelAspect()
script_data = {
"frameStart": first_frame + handle_start,
"frameEnd": last_frame - handle_end,
"resolutionWidth": resolution_width,
"resolutionHeight": resolution_height,
"pixelAspect": pixel_aspect,
# backward compatibility handles
"handles": handle_start,
"handleStart": handle_start,
"handleEnd": handle_end,
"step": 1,
"fps": root_node['fps'].value(),
"currentFile": current_file,
"version": int(api.get_version_from_path(current_file)),
"host": pyblish.api.current_host(),
"hostVersion": nuke.NUKE_VERSION_STRING
}
context.data["scriptData"] = script_data
context.data.update(script_data)
self.log.info('Context from Nuke script collected')

View file

@ -1,70 +1,25 @@
import os
import nuke
import pyblish.api
import openpype.api as api
from openpype.pipeline import KnownPublishError
class CollectWorkfile(pyblish.api.InstancePlugin):
"""Collect current script for publish."""
order = pyblish.api.CollectorOrder - 0.499
order = pyblish.api.CollectorOrder - 0.498
label = "Collect Workfile"
hosts = ['nuke']
families = ["workfile"]
def process(self, instance): # sourcery skip: avoid-builtin-shadow
root = nuke.root()
script_data = instance.context.data["scriptData"]
current_file = os.path.normpath(nuke.root().name())
if current_file.lower() == "root":
raise KnownPublishError(
"Workfile is not correct file name. \n"
"Use workfile tool to manage the name correctly."
)
# creating instances per write node
staging_dir = os.path.dirname(current_file)
base_name = os.path.basename(current_file)
# Get frame range
first_frame = int(root["first_frame"].getValue())
last_frame = int(root["last_frame"].getValue())
handle_start = instance.data["handleStart"]
handle_end = instance.data["handleEnd"]
# Get format
format = root['format'].value()
resolution_width = format.width()
resolution_height = format.height()
pixel_aspect = format.pixelAspect()
script_data = {
"frameStart": first_frame + handle_start,
"frameEnd": last_frame - handle_end,
"resolutionWidth": resolution_width,
"resolutionHeight": resolution_height,
"pixelAspect": pixel_aspect,
# backward compatibility handles
"handles": handle_start,
"handleStart": handle_start,
"handleEnd": handle_end,
"step": 1,
"fps": root['fps'].value(),
"currentFile": current_file,
"version": int(api.get_version_from_path(current_file)),
"host": pyblish.api.current_host(),
"hostVersion": nuke.NUKE_VERSION_STRING
}
instance.context.data.update(script_data)
# creating representation
representation = {
'name': 'nk',
@ -82,4 +37,4 @@ class CollectWorkfile(pyblish.api.InstancePlugin):
# adding basic script data
instance.data.update(script_data)
self.log.info('Publishing script version')
self.log.info("Collect script version")