mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 16:34:53 +01:00
filter instances without active parents
This commit is contained in:
parent
9792be3c84
commit
3c8f3224bc
1 changed files with 36 additions and 10 deletions
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
|
import collections
|
||||||
|
|
||||||
import pyblish.api
|
import pyblish.api
|
||||||
|
|
||||||
from ayon_core.host import IPublishHost
|
from ayon_core.host import IPublishHost
|
||||||
|
|
@ -36,18 +38,42 @@ class CollectFromCreateContext(pyblish.api.ContextPlugin):
|
||||||
if project_name:
|
if project_name:
|
||||||
context.data["projectName"] = project_name
|
context.data["projectName"] = project_name
|
||||||
|
|
||||||
|
# Filter active instances and skip instances which have disabled
|
||||||
|
# parent instance
|
||||||
|
instances_by_parent_id = collections.defaultdict(list)
|
||||||
|
filtered_instances = []
|
||||||
for created_instance in create_context.instances:
|
for created_instance in create_context.instances:
|
||||||
|
if not created_instance["active"]:
|
||||||
|
continue
|
||||||
|
parent_id = created_instance.parent_instance_id
|
||||||
|
if parent_id is None:
|
||||||
|
filtered_instances.append(created_instance)
|
||||||
|
else:
|
||||||
|
instances_by_parent_id[parent_id].append(created_instance)
|
||||||
|
|
||||||
|
parent_ids_queue = collections.deque()
|
||||||
|
parent_ids_queue.extend(
|
||||||
|
instance.id for instance in filtered_instances
|
||||||
|
)
|
||||||
|
while parent_ids_queue:
|
||||||
|
parent_id = parent_ids_queue.popleft()
|
||||||
|
children = instances_by_parent_id[parent_id]
|
||||||
|
if not children:
|
||||||
|
continue
|
||||||
|
filtered_instances.extend(children)
|
||||||
|
parent_ids_queue.extend(instance.id for instance in children)
|
||||||
|
|
||||||
|
for created_instance in filtered_instances:
|
||||||
instance_data = created_instance.data_to_store()
|
instance_data = created_instance.data_to_store()
|
||||||
if instance_data["active"]:
|
thumbnail_path = thumbnail_paths_by_instance_id.get(
|
||||||
thumbnail_path = thumbnail_paths_by_instance_id.get(
|
created_instance.id
|
||||||
created_instance.id
|
)
|
||||||
)
|
self.create_instance(
|
||||||
self.create_instance(
|
context,
|
||||||
context,
|
instance_data,
|
||||||
instance_data,
|
created_instance.transient_data,
|
||||||
created_instance.transient_data,
|
thumbnail_path
|
||||||
thumbnail_path
|
)
|
||||||
)
|
|
||||||
|
|
||||||
# Update global data to context
|
# Update global data to context
|
||||||
context.data.update(create_context.context_data_to_store())
|
context.data.update(create_context.context_data_to_store())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue