[Bf-extensions-cvs] [8b202fb6] master: Collection Manager: Improve remove collection operator. Task: T69577

Ryan Inch noreply at git.blender.org
Tue Jan 7 09:02:18 CET 2020


Commit: 8b202fb6dccb9dc67ea78bc525e2875f7b1f6345
Author: Ryan Inch
Date:   Tue Jan 7 02:58:56 2020 -0500
Branches: master
https://developer.blender.org/rBA8b202fb6dccb9dc67ea78bc525e2875f7b1f6345

Collection Manager: Improve remove collection operator. Task: T69577

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

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 e624083c..e5ca072f 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": (1,8,5),
+    "version": (1,8,6),
     "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 ce1c4178..7e65c9cb 100644
--- a/object_collection_manager/operators.py
+++ b/object_collection_manager/operators.py
@@ -993,78 +993,26 @@ class CMRemoveCollectionOperator(Operator):
 
         laycol = layer_collections[self.collection_name]
         collection = laycol["ptr"].collection
-        laycol_parent = laycol["parent"]
-
-        # save state and remove all hiding properties of parent collection
-        orig_parent_hide_select = False
-        orig_parent_exclude = False
-        orig_parent_hide_viewport = False
-
-        if laycol_parent["ptr"].collection.hide_select:
-            orig_parent_hide_select = True
-
-        if laycol_parent["ptr"].exclude:
-            orig_parent_exclude = True
-
-        if laycol_parent["ptr"].hide_viewport:
-            orig_parent_hide_viewport = True
-
-        laycol_parent["ptr"].collection.hide_select = False
-        laycol_parent["ptr"].exclude = False
-        laycol_parent["ptr"].hide_viewport = False
-
-
-        # remove all hiding properties of this collection
-        collection.hide_select = False
-        laycol["ptr"].exclude = False
-        laycol["ptr"].hide_viewport = False
+        parent_collection = laycol["parent"]["ptr"].collection
 
 
         # shift all objects in this collection to the parent collection
-        if collection.objects:
-            orig_selected_objs = context.selected_objects
-            orig_active_obj = context.active_object
-
-            # select all objects in collection
-            bpy.ops.object.select_same_collection(collection=collection.name)
-            context.view_layer.objects.active = context.selected_objects[0]
-
-            # remove any objects already in parent collection from selection
-            for obj in context.selected_objects:
-                if obj in laycol["parent"]["ptr"].collection.objects.values():
-                    obj.select_set(False)
-
-            # link selected objects to parent collection
-            bpy.ops.object.link_to_collection(collection_index=laycol_parent["id"])
-
-            # remove objects from collection
-            bpy.ops.collection.objects_remove(collection=collection.name)
-
-            # reset selection original values
-            bpy.ops.object.select_all(action='DESELECT')
-
-            for obj in orig_selected_objs:
-                obj.select_set(True)
-            context.view_layer.objects.active = orig_active_obj
+        for obj in collection.objects:
+            if obj.name not in parent_collection.objects:
+                parent_collection.objects.link(obj)
 
 
         # shift all child collections to the parent collection
         if collection.children:
             for subcollection in collection.children:
-                laycol_parent["ptr"].collection.children.link(subcollection)
-
-        # reset hiding properties of parent collection
-        laycol_parent["ptr"].collection.hide_select = orig_parent_hide_select
-        laycol_parent["ptr"].exclude = orig_parent_exclude
-        laycol_parent["ptr"].hide_viewport = orig_parent_hide_viewport
+                parent_collection.children.link(subcollection)
 
 
         # remove collection and update tree view
         bpy.data.collections.remove(collection)
-
-
         update_property_group(context)
 
+
         if len(context.scene.CMListCollection) == context.scene.CMListIndex:
             context.scene.CMListIndex = len(context.scene.CMListCollection) - 1
             update_property_group(context)



More information about the Bf-extensions-cvs mailing list