mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 16:34:53 +01:00
Merge pull request #5392 from ynput/bugfix/OP-6306_created_instances_subset_name
This commit is contained in:
commit
52a107e1ab
2 changed files with 45 additions and 9 deletions
|
|
@ -539,6 +539,8 @@ def list_instances(creator_id=None):
|
|||
"""
|
||||
instances_by_order = defaultdict(list)
|
||||
subset_instances = []
|
||||
instance_ids = set()
|
||||
|
||||
for node in nuke.allNodes(recurseGroups=True):
|
||||
|
||||
if node.Class() in ["Viewer", "Dot"]:
|
||||
|
|
@ -564,6 +566,14 @@ def list_instances(creator_id=None):
|
|||
if creator_id and instance_data["creator_identifier"] != creator_id:
|
||||
continue
|
||||
|
||||
if instance_data["instance_id"] in instance_ids:
|
||||
instance_data.pop("instance_id")
|
||||
else:
|
||||
instance_ids.add(instance_data["instance_id"])
|
||||
|
||||
# node name could change, so update subset name data
|
||||
_update_subset_name_data(instance_data, node)
|
||||
|
||||
if "render_order" not in node.knobs():
|
||||
subset_instances.append((node, instance_data))
|
||||
continue
|
||||
|
|
@ -572,23 +582,43 @@ def list_instances(creator_id=None):
|
|||
instances_by_order[order].append((node, instance_data))
|
||||
|
||||
# Sort instances based on order attribute or subset name.
|
||||
# TODO: remove in future Publisher enhanced with sorting
|
||||
ordered_instances = []
|
||||
for key in sorted(instances_by_order.keys()):
|
||||
instances_by_subset = {}
|
||||
for node, data in instances_by_order[key]:
|
||||
instances_by_subset[data["subset"]] = (node, data)
|
||||
instances_by_subset = defaultdict(list)
|
||||
for node, data_ in instances_by_order[key]:
|
||||
instances_by_subset[data_["subset"]].append((node, data_))
|
||||
for subkey in sorted(instances_by_subset.keys()):
|
||||
ordered_instances.append(instances_by_subset[subkey])
|
||||
ordered_instances.extend(instances_by_subset[subkey])
|
||||
|
||||
instances_by_subset = {}
|
||||
for node, data in subset_instances:
|
||||
instances_by_subset[data["subset"]] = (node, data)
|
||||
instances_by_subset = defaultdict(list)
|
||||
for node, data_ in subset_instances:
|
||||
instances_by_subset[data_["subset"]].append((node, data_))
|
||||
for key in sorted(instances_by_subset.keys()):
|
||||
ordered_instances.append(instances_by_subset[key])
|
||||
ordered_instances.extend(instances_by_subset[key])
|
||||
|
||||
return ordered_instances
|
||||
|
||||
|
||||
def _update_subset_name_data(instance_data, node):
|
||||
"""Update subset name data in instance data.
|
||||
|
||||
Args:
|
||||
instance_data (dict): instance creator data
|
||||
node (nuke.Node): nuke node
|
||||
"""
|
||||
# make sure node name is subset name
|
||||
old_subset_name = instance_data["subset"]
|
||||
old_variant = instance_data["variant"]
|
||||
subset_name_root = old_subset_name.replace(old_variant, "")
|
||||
|
||||
new_subset_name = node.name()
|
||||
new_variant = new_subset_name.replace(subset_name_root, "")
|
||||
|
||||
instance_data["subset"] = new_subset_name
|
||||
instance_data["variant"] = new_variant
|
||||
|
||||
|
||||
def remove_instance(instance):
|
||||
"""Remove instance from current workfile metadata.
|
||||
|
||||
|
|
|
|||
|
|
@ -212,9 +212,15 @@ class NukeCreator(NewCreator):
|
|||
created_instance["creator_attributes"].pop(key)
|
||||
|
||||
def update_instances(self, update_list):
|
||||
for created_inst, _changes in update_list:
|
||||
for created_inst, changes in update_list:
|
||||
instance_node = created_inst.transient_data["node"]
|
||||
|
||||
# update instance node name if subset name changed
|
||||
if "subset" in changes.changed_keys:
|
||||
instance_node["name"].setValue(
|
||||
changes["subset"].new_value
|
||||
)
|
||||
|
||||
# in case node is not existing anymore (user erased it manually)
|
||||
try:
|
||||
instance_node.fullName()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue