Skip to content

Commit

Permalink
better recursive get collec children
Browse files Browse the repository at this point in the history
  • Loading branch information
Pullusb committed Jul 4, 2023
1 parent 9cdaf87 commit eefb110
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions snippets/bpy/get_all_childs_collections_recursive.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
def get_collection_childs_recursive(col, cols=[]):
'''return a list of all the sub-collections in passed col'''
# Start from fresh list, otherwise uncleared "cols" list is used on next call
## Get all children collection recursively

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_childs_recursive(sub, cols)
cols = get_collection_children_recursive(sub, cols)
return cols

# get_collection_children_recursive(bpy.context.scene.collection)

0 comments on commit eefb110

Please sign in to comment.