Initial code for collection confo operator
This commit is contained in:
@@ -305,7 +305,7 @@ def connect_to_file_output(node_list, file_out=None, base_path='', excludes=None
|
||||
# endregion
|
||||
|
||||
|
||||
# region Utilities
|
||||
# region Collections
|
||||
|
||||
def get_collection_children_recursive(col, cols=None) -> list:
|
||||
'''return a list of all the child collections
|
||||
@@ -319,6 +319,51 @@ def get_collection_children_recursive(col, cols=None) -> list:
|
||||
cols = get_collection_children_recursive(sub, cols)
|
||||
return cols
|
||||
|
||||
def get_view_layer_collection(col, vl_col=None, view_layer=None):
|
||||
'''return viewlayer collection from collection
|
||||
col: the collection to get viewlayer collection from
|
||||
view_layer (viewlayer, optional) : viewlayer to search in, if not passed, use active viewlayer
|
||||
|
||||
'''
|
||||
if vl_col is None:
|
||||
if view_layer:
|
||||
vl_col = view_layer.layer_collection
|
||||
else:
|
||||
vl_col = bpy.context.view_layer.layer_collection
|
||||
for sub in vl_col.children:
|
||||
if sub.collection == col:
|
||||
return sub
|
||||
if len(sub.children):
|
||||
c = get_view_layer_collection(col, sub)
|
||||
if c is not None:
|
||||
return c
|
||||
|
||||
def get_parents_cols(col, root=None, scene=None, cols=None):
|
||||
'''Return a list of parents collections of passed col
|
||||
root : Pass a collection to search in (recursive)
|
||||
Else search in master collection
|
||||
scene: scene to search in (active scene if not passed)
|
||||
cols: used internally by the function to collect results
|
||||
'''
|
||||
if cols is None:
|
||||
cols = []
|
||||
|
||||
if root == None:
|
||||
scn = scene or bpy.context.scene
|
||||
root=scn.collection
|
||||
|
||||
for sub in root.children:
|
||||
if sub == col:
|
||||
cols.append(root)
|
||||
|
||||
if len(sub.children):
|
||||
cols = get_parents_cols(col, root=sub, cols=cols)
|
||||
return cols
|
||||
|
||||
# endregion
|
||||
|
||||
# region utilities
|
||||
|
||||
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:
|
||||
|
||||
Reference in New Issue
Block a user