Skip to content

Commit

Permalink
implement separate update_instances function for NukeWriteCreator
Browse files Browse the repository at this point in the history
  • Loading branch information
moonyuet committed Jul 26, 2024
1 parent b716e71 commit da7b3ee
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 28 deletions.
28 changes: 28 additions & 0 deletions client/ayon_nuke/api/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import re
import json
import six
import copy
import functools
import warnings
import platform
Expand Down Expand Up @@ -2971,3 +2972,30 @@ def link_knobs(knobs, node, group_node):
"Write node exposed knobs missing:\n\n{}\n\nPlease review"
" project settings.".format("\n".join(missing_knobs))
)


def reset_write_node_filepath(instance_node, data):
"""Reset filepath in the write node when switching folderPath and task
Args:
instance_node (nuke.Nodes): instance node
data (dict): instance data
"""
formatting_data = copy.deepcopy(data)
write_node = nuke.allNodes(group=instance_node, filter="Write")[0]
formatting_data.update({
"fpath_template": (
"{work}/renders/nuke/{subset}/{subset}.{frame}.{ext}"),
"ext": write_node["file_type"].value()
})
anatomy_filled = format_anatomy(formatting_data)

# build file path to workfiles
fdir = str(
anatomy_filled["work"]["default"]["directory"]
).replace("\\", "/")
formatting_data["work"] = fdir
fpath = StringTemplate(formatting_data["fpath_template"]).format_strict(
formatting_data)
write_node["file"].setValue(fpath)
instance_node["name"].setValue(formatting_data["productName"])
34 changes: 34 additions & 0 deletions client/ayon_nuke/api/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
get_node_data,
get_view_process_node,
get_filenames_without_hash,
reset_write_node_filepath,
link_knobs
)
from .pipeline import (
Expand Down Expand Up @@ -309,6 +310,39 @@ def set_selected_nodes(self, pre_create_data):
else:
self.selected_node = None

def update_instances(self, update_list):
for created_inst, changes in update_list:
instance_node = created_inst.transient_data["node"]

# update instance node name if product name changed
if "productName" in changes.changed_keys:
changed_data = {
"productName": changes["productName"].new_value or (
created_inst["productName"]),
"folderPath": changes["folderPath"].new_value or (
created_inst["folderPath"]
),
"task": changes["task"].new_value or (
created_inst["task"]
),
"productType": changes["productType"].new_value or (
created_inst["productType"]
)
}
reset_write_node_filepath(instance_node, changed_data)
# in case node is not existing anymore (user erased it manually)
try:
instance_node.fullName()
except ValueError:
self.remove_instances([created_inst])
continue

set_node_data(
instance_node,
INSTANCE_DATA_KNOB,
created_inst.data_to_store()
)

def get_pre_create_attr_defs(self):
attr_defs = [
BoolDef("use_selection", label="Use selection"),
Expand Down
45 changes: 17 additions & 28 deletions client/ayon_nuke/plugins/publish/validate_asset_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
from __future__ import absolute_import

import pyblish.api
import nuke
from ayon_core.lib import StringTemplate

from ayon_core.pipeline.publish import (
RepairAction,
ValidateContentsOrder,
PublishXmlValidationError,
OptionalPyblishPluginMixin
)
from ayon_nuke.api import SelectInstanceNodeAction
from ayon_nuke.api.lib import format_anatomy
from ayon_nuke.api.lib import reset_write_node_filepath


class ValidateCorrectAssetContext(
Expand Down Expand Up @@ -112,29 +111,19 @@ def repair(cls, instance):
)
for _key in invalid_keys:
created_instance[_key] = instance.context.data[_key]
create_context.save_changes()
if instance.data["productType"] in {"prerender", "render", "image"}:
cls.reset_write_node_filepath(instance)

@classmethod
def reset_write_node_filepath(cls, instance):
instance_node = instance.data["transientData"]["node"]
write_node = nuke.allNodes(group=instance_node, filter="Write")[0]
data = dict({
"fpath_template": (
"{work}/renders/nuke/{subset}/{subset}.{frame}.{ext}"),
"ext": write_node["file_type"].value(),
"folderPath": instance.context.data["folderPath"],
"task": instance.context.data["task"],
"productName": instance.data["productName"],
"productType": instance.data["productType"]
})
anatomy_filled = format_anatomy(data)

# build file path to workfiles
fdir = str(
anatomy_filled["work"]["default"]["directory"]
).replace("\\", "/")
data["work"] = fdir
fpath = StringTemplate(data["fpath_template"]).format_strict(data)
write_node["file"].setValue(fpath)
if instance.data["productType"] in {"prerender", "render", "image"}:
updated_created_instance = create_context.get_instance_by_id(
instance_id
)
instance_node = instance.data["transientData"]["node"]
data = dict({
"folderPath": updated_created_instance["folderPath"],
"task": updated_created_instance["task"],
"productName": updated_created_instance["productName"],
"productType": updated_created_instance["productType"]
})

reset_write_node_filepath(instance_node, data)

create_context.save_changes()

0 comments on commit da7b3ee

Please sign in to comment.