diff --git a/object_collection_manager/__init__.py b/object_collection_manager/__init__.py index e624083cb17a726584bf5e4dadf6fb325d5c63e0..e5ca072fe26bf8420944077927da0fa2f1382c28 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 ce1c4178b8986a8b1b5cec30400d5885340087b2..7e65c9cb21622ccfe5abd64cde88aa0239943073 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)