Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #6137 from tokejepsen/enhancement/OP-7592_expose_w…
Browse files Browse the repository at this point in the history
…rite_knobs

Nuke: Expose write knobs - OP-7592
  • Loading branch information
jakubjezek001 authored Jan 31, 2024
2 parents 9a12910 + 94dddd0 commit c81e139
Show file tree
Hide file tree
Showing 10 changed files with 146 additions and 7 deletions.
4 changes: 3 additions & 1 deletion openpype/hosts/nuke/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
get_node_data,
set_node_data,
update_node_data,
create_write_node
create_write_node,
link_knobs
)
from .utils import (
colorspace_exists_on_node,
Expand Down Expand Up @@ -95,6 +96,7 @@
"set_node_data",
"update_node_data",
"create_write_node",
"link_knobs",

"colorspace_exists_on_node",
"get_colorspace_list",
Expand Down
24 changes: 24 additions & 0 deletions openpype/hosts/nuke/api/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -3499,3 +3499,27 @@ def create_camera_node_by_version():
return nuke.createNode("Camera4")
else:
return nuke.createNode("Camera2")


def link_knobs(knobs, node, group_node):
"""Link knobs from inside `group_node`"""

missing_knobs = []
for knob in knobs:
if knob in group_node.knobs():
continue

if knob not in node.knobs().keys():
missing_knobs.append(knob)

link = nuke.Link_Knob("")
link.makeLink(node.name(), knob)
link.setName(knob)
link.setFlag(0x1000)
group_node.addKnob(link)

if missing_knobs:
raise ValueError(
"Write node exposed knobs missing:\n\n{}\n\nPlease review"
" project settings.".format("\n".join(missing_knobs))
)
11 changes: 10 additions & 1 deletion openpype/hosts/nuke/api/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
get_view_process_node,
get_viewer_config_from_string,
deprecated,
get_filenames_without_hash
get_filenames_without_hash,
link_knobs
)
from .pipeline import (
list_instances,
Expand Down Expand Up @@ -1344,3 +1345,11 @@ def _remove_old_knobs(node):
node.removeKnob(knob)
except ValueError:
pass


def exposed_write_knobs(settings, plugin_name, instance_node):
exposed_knobs = settings["nuke"]["create"][plugin_name]["exposed_knobs"]
if exposed_knobs:
instance_node.addKnob(nuke.Text_Knob('', 'Write Knobs'))
write_node = nuke.allNodes(group=instance_node, filter="Write")[0]
link_knobs(exposed_knobs, write_node, instance_node)
5 changes: 5 additions & 0 deletions openpype/hosts/nuke/plugins/create/create_write_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
EnumDef
)
from openpype.hosts.nuke import api as napi
from openpype.hosts.nuke.api.plugin import exposed_write_knobs


class CreateWriteImage(napi.NukeWriteCreator):
Expand Down Expand Up @@ -132,6 +133,10 @@ def create(self, subset_name, instance_data, pre_create_data):
instance.data_to_store()
)

exposed_write_knobs(
self.project_settings, self.__class__.__name__, instance_node
)

return instance

except Exception as er:
Expand Down
5 changes: 5 additions & 0 deletions openpype/hosts/nuke/plugins/create/create_write_prerender.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
BoolDef
)
from openpype.hosts.nuke import api as napi
from openpype.hosts.nuke.api.plugin import exposed_write_knobs


class CreateWritePrerender(napi.NukeWriteCreator):
Expand Down Expand Up @@ -119,6 +120,10 @@ def create(self, subset_name, instance_data, pre_create_data):
instance.data_to_store()
)

exposed_write_knobs(
self.project_settings, self.__class__.__name__, instance_node
)

return instance

except Exception as er:
Expand Down
5 changes: 5 additions & 0 deletions openpype/hosts/nuke/plugins/create/create_write_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
BoolDef
)
from openpype.hosts.nuke import api as napi
from openpype.hosts.nuke.api.plugin import exposed_write_knobs


class CreateWriteRender(napi.NukeWriteCreator):
Expand Down Expand Up @@ -113,6 +114,10 @@ def create(self, subset_name, instance_data, pre_create_data):
instance.data_to_store()
)

exposed_write_knobs(
self.project_settings, self.__class__.__name__, instance_node
)

return instance

except Exception as er:
Expand Down
77 changes: 77 additions & 0 deletions openpype/hosts/nuke/plugins/publish/validate_exposed_knobs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import pyblish.api

from openpype.pipeline.publish import get_errored_instances_from_context
from openpype.hosts.nuke.api.lib import link_knobs
from openpype.pipeline.publish import (
OptionalPyblishPluginMixin,
PublishValidationError
)


class RepairExposedKnobs(pyblish.api.Action):
label = "Repair"
on = "failed"
icon = "wrench"

def process(self, context, plugin):
instances = get_errored_instances_from_context(context)

for instance in instances:
child_nodes = (
instance.data.get("transientData", {}).get("childNodes")
or instance
)

write_group_node = instance.data["transientData"]["node"]
# get write node from inside of group
write_node = None
for x in child_nodes:
if x.Class() == "Write":
write_node = x

plugin_name = plugin.families_mapping[instance.data["family"]]
nuke_settings = instance.context.data["project_settings"]["nuke"]
create_settings = nuke_settings["create"][plugin_name]
exposed_knobs = create_settings["exposed_knobs"]
link_knobs(exposed_knobs, write_node, write_group_node)


class ValidateExposedKnobs(
OptionalPyblishPluginMixin,
pyblish.api.InstancePlugin
):
""" Validate write node exposed knobs.
Compare exposed linked knobs to settings.
"""

order = pyblish.api.ValidatorOrder
optional = True
families = ["render", "prerender", "image"]
label = "Validate Exposed Knobs"
actions = [RepairExposedKnobs]
hosts = ["nuke"]
families_mapping = {
"render": "CreateWriteRender",
"prerender": "CreateWritePrerender",
"image": "CreateWriteImage"
}

def process(self, instance):
if not self.is_active(instance.data):
return

plugin = self.families_mapping[instance.data["family"]]
group_node = instance.data["transientData"]["node"]
nuke_settings = instance.context.data["project_settings"]["nuke"]
create_settings = nuke_settings["create"][plugin]
exposed_knobs = create_settings["exposed_knobs"]
unexposed_knobs = []
for knob in exposed_knobs:
if knob not in group_node.knobs():
unexposed_knobs.append(knob)

if unexposed_knobs:
raise PublishValidationError(
"Missing exposed knobs: {}".format(unexposed_knobs)
)
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from openpype.pipeline.publish import (
PublishXmlValidationError,
OptionalPyblishPluginMixin,
OptionalPyblishPluginMixin
)


Expand Down
18 changes: 15 additions & 3 deletions server_addon/nuke/server/settings/create_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ class CreateWriteRenderModel(BaseSettingsModel):
enum_resolver=instance_attributes_enum,
title="Instance attributes"
)

exposed_knobs: list[str] = SettingsField(
title="Write Node Exposed Knobs",
default_factory=list
)
prenodes: list[PrenodeModel] = SettingsField(
default_factory=list,
title="Preceding nodes",
Expand All @@ -81,7 +84,10 @@ class CreateWritePrerenderModel(BaseSettingsModel):
enum_resolver=instance_attributes_enum,
title="Instance attributes"
)

exposed_knobs: list[str] = SettingsField(
title="Write Node Exposed Knobs",
default_factory=list
)
prenodes: list[PrenodeModel] = SettingsField(
default_factory=list,
title="Preceding nodes",
Expand All @@ -107,7 +113,10 @@ class CreateWriteImageModel(BaseSettingsModel):
enum_resolver=instance_attributes_enum,
title="Instance attributes"
)

exposed_knobs: list[str] = SettingsField(
title="Write Node Exposed Knobs",
default_factory=list
)
prenodes: list[PrenodeModel] = SettingsField(
default_factory=list,
title="Preceding nodes",
Expand Down Expand Up @@ -146,6 +155,7 @@ class CreatorPluginsSettings(BaseSettingsModel):
"reviewable",
"farm_rendering"
],
"exposed_knobs": [],
"prenodes": [
{
"name": "Reformat01",
Expand Down Expand Up @@ -179,6 +189,7 @@ class CreatorPluginsSettings(BaseSettingsModel):
"farm_rendering",
"use_range_limit"
],
"exposed_knobs": [],
"prenodes": []
},
"CreateWriteImage": {
Expand All @@ -191,6 +202,7 @@ class CreatorPluginsSettings(BaseSettingsModel):
"instance_attributes": [
"use_range_limit"
],
"exposed_knobs": [],
"prenodes": [
{
"name": "FrameHold01",
Expand Down
2 changes: 1 addition & 1 deletion server_addon/nuke/server/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.1.8"
__version__ = "0.1.9"

0 comments on commit c81e139

Please sign in to comment.