mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-30 08:33:10 +00:00
Fix #1925. Fix bug where nested collection deletions were not synchronised properly.
This commit is contained in:
@@ -379,41 +379,66 @@ class OverrideOutlinerDelete(bpy.types.Operator, OverrideDeleteTrait):
|
|||||||
return len(context.selected_ids) > 0
|
return len(context.selected_ids) > 0
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
|
# In this override, we don't check self.hierarchy. This effectively
|
||||||
|
# makes Delete and Delete Hierarchy identical. This is on purpose, since
|
||||||
|
# non-hierarchical deletion may imply a whole bunch of potentially
|
||||||
|
# unintended IFC spatial modifications. To make life less confusing for
|
||||||
|
# the user, Delete means Delete. End of story.
|
||||||
# Deep magick from the dawn of time
|
# Deep magick from the dawn of time
|
||||||
if IfcStore.get_file():
|
if IfcStore.get_file():
|
||||||
return IfcStore.execute_ifc_operator(self, context)
|
return IfcStore.execute_ifc_operator(self, context)
|
||||||
# https://blender.stackexchange.com/questions/203729/python-get-selected-objects-in-outliner
|
# https://blender.stackexchange.com/questions/203729/python-get-selected-objects-in-outliner
|
||||||
objects_to_delete = set()
|
objects_to_delete = set()
|
||||||
|
collections_to_delete = set()
|
||||||
for item in context.selected_ids:
|
for item in context.selected_ids:
|
||||||
if item.bl_rna.identifier == "Collection":
|
if item.bl_rna.identifier == "Collection":
|
||||||
collection = bpy.data.collections.get(item.name)
|
collection = bpy.data.collections.get(item.name)
|
||||||
if self.hierarchy:
|
collection_data = self.get_collection_objects_and_children(collection)
|
||||||
for obj in collection.objects:
|
print(collection_data)
|
||||||
objects_to_delete.add(bpy.data.objects.get(item.name))
|
objects_to_delete |= collection_data["objects"]
|
||||||
bpy.data.collections.remove(collection)
|
collections_to_delete |= collection_data["children"]
|
||||||
|
collections_to_delete.add(collection)
|
||||||
elif item.bl_rna.identifier == "Object":
|
elif item.bl_rna.identifier == "Object":
|
||||||
objects_to_delete.add(bpy.data.objects.get(item.name))
|
objects_to_delete.add(bpy.data.objects.get(item.name))
|
||||||
for obj in objects_to_delete:
|
for obj in objects_to_delete:
|
||||||
bpy.data.objects.remove(obj)
|
bpy.data.objects.remove(obj)
|
||||||
|
for collection in collections_to_delete:
|
||||||
|
bpy.data.collections.remove(collection)
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
def _execute(self, context):
|
def _execute(self, context):
|
||||||
objects_to_delete = set()
|
objects_to_delete = set()
|
||||||
|
collections_to_delete = set()
|
||||||
for item in context.selected_ids:
|
for item in context.selected_ids:
|
||||||
if item.bl_rna.identifier == "Collection":
|
if item.bl_rna.identifier == "Collection":
|
||||||
collection = bpy.data.collections.get(item.name)
|
collection = bpy.data.collections.get(item.name)
|
||||||
if self.hierarchy:
|
collection_data = self.get_collection_objects_and_children(collection)
|
||||||
for obj in collection.objects:
|
objects_to_delete |= collection_data["objects"]
|
||||||
objects_to_delete.add(bpy.data.objects.get(item.name))
|
collections_to_delete |= collection_data["children"]
|
||||||
bpy.data.collections.remove(collection)
|
collections_to_delete.add(collection)
|
||||||
elif item.bl_rna.identifier == "Object":
|
elif item.bl_rna.identifier == "Object":
|
||||||
objects_to_delete.add(bpy.data.objects.get(item.name))
|
objects_to_delete.add(bpy.data.objects.get(item.name))
|
||||||
for obj in objects_to_delete:
|
for obj in objects_to_delete:
|
||||||
# This is the only difference
|
# This is the only difference
|
||||||
self.delete_ifc_object(obj)
|
self.delete_ifc_object(obj)
|
||||||
bpy.data.objects.remove(obj)
|
bpy.data.objects.remove(obj)
|
||||||
|
for collection in collections_to_delete:
|
||||||
|
bpy.data.collections.remove(collection)
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
def get_collection_objects_and_children(self, collection):
|
||||||
|
objects = set()
|
||||||
|
children = set()
|
||||||
|
queue = [collection]
|
||||||
|
while queue:
|
||||||
|
collection = queue.pop()
|
||||||
|
for obj in collection.objects:
|
||||||
|
print('obj is', obj)
|
||||||
|
objects.add(obj)
|
||||||
|
queue.extend(collection.children)
|
||||||
|
children = children.union(collection.children)
|
||||||
|
return {"objects": objects, "children": children}
|
||||||
|
|
||||||
|
|
||||||
class OverrideDuplicateMove(bpy.types.Operator):
|
class OverrideDuplicateMove(bpy.types.Operator):
|
||||||
bl_idname = "object.duplicate_move"
|
bl_idname = "object.duplicate_move"
|
||||||
|
|||||||
Reference in New Issue
Block a user