move get collection recursive in functions so it can be reused

This commit is contained in:
pullusb 2025-07-23 14:55:50 +02:00
parent 01ccbbac30
commit 96875b43c5
2 changed files with 19 additions and 22 deletions

12
fn.py
View File

@ -307,6 +307,18 @@ def connect_to_file_output(node_list, file_out=None, base_path='', excludes=None
# region Utilities # 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): def set_properties_editor_tab(tab, skip_if_exists=True):
'''Take a tab name and apply it to properties editor '''Take a tab name and apply it to properties editor
tab: identifier of the tab, possible name in: tab: identifier of the tab, possible name in:

View File

@ -1,5 +1,4 @@
import bpy import bpy
from bpy.types import Operator from bpy.types import Operator
from bpy.props import (BoolProperty, from bpy.props import (BoolProperty,
EnumProperty, EnumProperty,
@ -7,6 +6,8 @@ from bpy.props import (BoolProperty,
CollectionProperty, CollectionProperty,
StringProperty) StringProperty)
from .. import fn
# region Object visibility # region Object visibility
@ -333,25 +334,14 @@ class RT_OT_list_viewport_render_visibility(Operator):
# region Collection Visibility # 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): def get_viewlayer_collections_with_visiblity_conflict(context):
'''return viewlayer collections with visibility conflicts between hide in viewlayer, hide viewport and hide render''' '''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 = fn.get_collection_children_recursive(context.view_layer.layer_collection)
vcols = list(set(vcols)) # ensure no duplicates vcols = list(set(vcols)) # ensure no duplicates
## Store collection with conflicts ## Store collection with conflicts
return [vc for vc in vcols if not (vc.hide_viewport == vc.collection.hide_viewport == vc.collection.hide_render)] 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): class RT_OT_list_collection_visibility_conflicts(Operator):
bl_idname = "rt.list_collection_visibility_conflicts" bl_idname = "rt.list_collection_visibility_conflicts"
@ -374,11 +364,6 @@ class RT_OT_list_collection_visibility_conflicts(Operator):
## get all viewlayer collections ## get all viewlayer collections
self.conflict_collections = get_viewlayer_collections_with_visiblity_conflict(context) 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.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] self.excluded_collection = [vc for vc in self.conflict_collections if vc.exclude]