diff --git a/fn.py b/fn.py index 30dc2b6..7cd0b6c 100755 --- a/fn.py +++ b/fn.py @@ -307,6 +307,18 @@ def connect_to_file_output(node_list, file_out=None, base_path='', excludes=None # region Utilities +def get_collection_children_recursive(col, cols=None) -> list: + '''return a list of all the child collections + and their subcollections in the passed collection''' + + cols = cols if cols is not None else [] + for sub in col.children: + if sub not in cols: + cols.append(sub) + if len(sub.children): + cols = get_collection_children_recursive(sub, cols) + return cols + def set_properties_editor_tab(tab, skip_if_exists=True): '''Take a tab name and apply it to properties editor tab: identifier of the tab, possible name in: diff --git a/operators/visibility_conflicts.py b/operators/visibility_conflicts.py index a4b24d4..ede174d 100644 --- a/operators/visibility_conflicts.py +++ b/operators/visibility_conflicts.py @@ -1,5 +1,4 @@ import bpy - from bpy.types import Operator from bpy.props import (BoolProperty, EnumProperty, @@ -7,6 +6,8 @@ from bpy.props import (BoolProperty, CollectionProperty, StringProperty) +from .. import fn + # region Object visibility @@ -333,25 +334,14 @@ class RT_OT_list_viewport_render_visibility(Operator): # region Collection Visibility -def get_collection_children_recursive(col, cols=None) -> list: - '''return a list of all the child collections - and their subcollections in the passed collection''' - - cols = cols or [] - for sub in col.children: - if sub not in cols: - cols.append(sub) - if len(sub.children): - cols = get_collection_children_recursive(sub, cols) - return cols def get_viewlayer_collections_with_visiblity_conflict(context): - '''return viewlayer collections with visibility conflicts between hide in viewlayer, hide viewport and hide render''' - vcols = get_collection_children_recursive(context.view_layer.layer_collection) - vcols = list(set(vcols)) # ensure no duplicates + '''return viewlayer collections with visibility conflicts between hide in viewlayer, hide viewport and hide render''' + vcols = fn.get_collection_children_recursive(context.view_layer.layer_collection) + vcols = list(set(vcols)) # ensure no duplicates - ## Store collection with conflicts - return [vc for vc in vcols if not (vc.hide_viewport == vc.collection.hide_viewport == vc.collection.hide_render)] + ## Store collection with conflicts + return [vc for vc in vcols if not (vc.hide_viewport == vc.collection.hide_viewport == vc.collection.hide_render)] class RT_OT_list_collection_visibility_conflicts(Operator): bl_idname = "rt.list_collection_visibility_conflicts" @@ -374,11 +364,6 @@ class RT_OT_list_collection_visibility_conflicts(Operator): ## get all viewlayer collections self.conflict_collections = get_viewlayer_collections_with_visiblity_conflict(context) - vcols = get_collection_children_recursive(context.view_layer.layer_collection) - vcols = list(set(vcols)) # ensure no duplicates - - ## Store collection with conflicts - self.conflict_collections = [vc for vc in vcols if not (vc.hide_viewport == vc.collection.hide_viewport == vc.collection.hide_render)] self.included_collection = [vc for vc in self.conflict_collections if not vc.exclude] self.excluded_collection = [vc for vc in self.conflict_collections if vc.exclude]