[Bf-extensions-cvs] [969e77ed] master: Collection Manager: Fix remove operator. Task: T69577

Ryan Inch noreply at git.blender.org
Fri Jul 3 09:16:35 CEST 2020


Commit: 969e77eda1fe42088db5198d8fc18281ce5efb2b
Author: Ryan Inch
Date:   Fri Jul 3 03:13:10 2020 -0400
Branches: master
https://developer.blender.org/rBA969e77eda1fe42088db5198d8fc18281ce5efb2b

Collection Manager: Fix remove operator. Task: T69577

Fixes the remove operator not preserving View Layer RTOs for
the children of the deleted collection.

===================================================================

M	object_collection_manager/__init__.py
M	object_collection_manager/operators.py

===================================================================

diff --git a/object_collection_manager/__init__.py b/object_collection_manager/__init__.py
index 91901c6f..7b32e00e 100644
--- a/object_collection_manager/__init__.py
+++ b/object_collection_manager/__init__.py
@@ -22,7 +22,7 @@ bl_info = {
     "name": "Collection Manager",
     "description": "Manage collections and their objects",
     "author": "Ryan Inch",
-    "version": (2, 9, 0),
+    "version": (2, 9, 1),
     "blender": (2, 80, 0),
     "location": "View3D - Object Mode (Shortcut - M)",
     "warning": '',  # used for warning icon and text in addons panel
diff --git a/object_collection_manager/operators.py b/object_collection_manager/operators.py
index 9958f96f..54f9596b 100644
--- a/object_collection_manager/operators.py
+++ b/object_collection_manager/operators.py
@@ -883,11 +883,35 @@ class CMRemoveCollectionOperator(Operator):
                 parent_collection.objects.link(obj)
 
 
-        # shift all child collections to the parent collection
+        # shift all child collections to the parent collection preserving view layer RTOs
         if collection.children:
+            # store view layer RTOs for all children of the to be deleted collection
+            child_states = {}
+            def get_child_states(layer_collection):
+                child_states[layer_collection.name] = (layer_collection.exclude,
+                                                       layer_collection.hide_viewport,
+                                                       layer_collection.holdout,
+                                                       layer_collection.indirect_only)
+
+            apply_to_children(laycol["ptr"], get_child_states)
+
+            # link any subcollections of the to be deleted collection to it's parent
             for subcollection in collection.children:
                 parent_collection.children.link(subcollection)
 
+            # apply the stored view layer RTOs to the newly linked collections and their
+            # children
+            def restore_child_states(layer_collection):
+                state = child_states.get(layer_collection.name)
+
+                if state:
+                    layer_collection.exclude = state[0]
+                    layer_collection.hide_viewport = state[1]
+                    layer_collection.holdout = state[2]
+                    layer_collection.indirect_only = state[3]
+
+            apply_to_children(laycol["parent"]["ptr"], restore_child_states)
+
 
         # remove collection, update expanded, and update tree view
         bpy.data.collections.remove(collection)



More information about the Bf-extensions-cvs mailing list