Deleting a spatial or aggregated element now also removes its collection

This commit is contained in:
Dion Moult
2023-01-09 16:46:51 +11:00
parent 745709c56a
commit b699f55d9c
@@ -362,23 +362,35 @@ class CopyRepresentation(bpy.types.Operator, Operator):
class OverrideDeleteTrait: class OverrideDeleteTrait:
def delete_ifc_object(self, obj): def delete_ifc_object(self, obj):
element = tool.Ifc.get_entity(obj) element = tool.Ifc.get_entity(obj)
if element: if not element:
IfcStore.delete_element(element) return
if getattr(element, "FillsVoids", None): IfcStore.delete_element(element)
self.remove_filling(element) if obj.users_collection and obj.users_collection[0].name == obj.name:
if element.is_a("IfcOpeningElement"): parent = ifcopenshell.util.element.get_aggregate(element)
if element.HasFillings: if not parent:
for rel in element.HasFillings: parent = ifcopenshell.util.element.get_container(element)
self.remove_filling(rel.RelatedBuildingElement) if parent:
else: parent_obj = tool.Ifc.get_object(parent)
if element.VoidsElements: if parent_obj:
self.delete_opening_element(element) parent_collection = bpy.data.collections.get(parent_obj.name)
for child in obj.users_collection[0].children:
parent_collection.children.link(child)
bpy.data.collections.remove(obj.users_collection[0])
if getattr(element, "FillsVoids", None):
self.remove_filling(element)
if element.is_a("IfcOpeningElement"):
if element.HasFillings:
for rel in element.HasFillings:
self.remove_filling(rel.RelatedBuildingElement)
else: else:
if getattr(element, "HasOpenings", None): if element.VoidsElements:
for rel in element.HasOpenings: self.delete_opening_element(element)
self.delete_opening_element(rel.RelatedOpeningElement) else:
for port in ifcopenshell.util.system.get_ports(element): if getattr(element, "HasOpenings", None):
self.remove_port(port) for rel in element.HasOpenings:
self.delete_opening_element(rel.RelatedOpeningElement)
for port in ifcopenshell.util.system.get_ports(element):
self.remove_port(port)
def delete_opening_element(self, element): def delete_opening_element(self, element):
bpy.ops.bim.remove_opening(opening_id=element.id()) bpy.ops.bim.remove_opening(opening_id=element.id())
@@ -479,8 +491,6 @@ class OverrideOutlinerDelete(bpy.types.Operator, OverrideDeleteTrait):
# 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): def get_collection_objects_and_children(self, collection):