-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
better recursive get collec children
- Loading branch information
Showing
1 changed file
with
9 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |