Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repair action from validate correct asset context to fix the write node's filepath #8

60 changes: 60 additions & 0 deletions client/ayon_nuke/api/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import sys
import six
import copy
import random
import string
from collections import defaultdict
Expand Down Expand Up @@ -46,6 +47,7 @@
list_instances,
remove_instance
)
from ayon_nuke.api.lib import format_anatomy


def _collect_and_cache_nodes(creator):
Expand Down Expand Up @@ -309,6 +311,30 @@ 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"]

# in case node is not existing anymore (user erased it manually)
try:
instance_node.fullName()
except ValueError:
self.remove_instances([created_inst])
continue
# update instance node name if product name changed
if "productName" in changes.changed_keys:
instance_node["name"].setValue(
changes["productName"].new_value
)

update_write_node_filepath(created_inst, changes)

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 Expand Up @@ -1225,3 +1251,37 @@ def exposed_write_knobs(settings, plugin_name, instance_node):
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)


def update_write_node_filepath(created_inst, changes):
moonyuet marked this conversation as resolved.
Show resolved Hide resolved
"""Update instance node on context changes.

Whenever any of productName, folderPath, task or productType
changes then update:
- output filepath of the write node
- instance node's name to the product name
"""
keys = ("productName", "folderPath", "task", "productType")
if not any(key in changes.changed_keys for key in keys):
# No relevant changes, no need to update
return
data = created_inst.data_to_store()
# Update values with new formatted path
instance_node = created_inst.transient_data["node"]
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)