diff options
Diffstat (limited to 'rigify/legacy/utils.py')
-rw-r--r-- | rigify/legacy/utils.py | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/rigify/legacy/utils.py b/rigify/legacy/utils.py index 632dcb26..f74a7abf 100644 --- a/rigify/legacy/utils.py +++ b/rigify/legacy/utils.py @@ -937,13 +937,13 @@ def random_id(length=8): return text -def get_layer_collection_from_collection(children, collection): - for layer_collection in children: - if collection == layer_collection.collection: - return layer_collection +def find_layer_collection_by_collection(layer_collection, collection): + if collection == layer_collection.collection: + return layer_collection - # go recursive - layer_collection = get_layer_collection_from_collection(layer_collection.children, collection) + # go recursive + for child in layer_collection.children: + layer_collection = find_layer_collection_by_collection(child, collection) if layer_collection: return layer_collection @@ -963,12 +963,14 @@ def ensure_widget_collection(context): widget_collection.hide_viewport = True widget_collection.hide_render = True + widget_layer_collection = None + else: + widget_layer_collection = find_layer_collection_by_collection(view_layer.layer_collection, widget_collection) + + if not widget_layer_collection: + # Add the widget collection to the tree collection.children.link(widget_collection) widget_layer_collection = [c for c in layer_collection.children if c.collection == widget_collection][0] - elif widget_collection == view_layer.layer_collection.collection: - widget_layer_collection = view_layer.layer_collection - else: - widget_layer_collection = get_layer_collection_from_collection(view_layer.layer_collection.children, widget_collection) # Make the widget the active collection for the upcoming added (widget) objects view_layer.active_layer_collection = widget_layer_collection |