From 6810bbff2f378812d81b64fb3b5d92bff5330575 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Fri, 14 Jul 2023 10:20:30 +0500 Subject: [PATCH] remove_product to remove IfcRelConnectsElements --- src/blenderbim/blenderbim/tool/geometry.py | 5 --- .../ifcopenshell/api/root/remove_product.py | 6 +++- .../test/api/root/test_remove_product.py | 34 +++++++++++++++++++ 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/src/blenderbim/blenderbim/tool/geometry.py b/src/blenderbim/blenderbim/tool/geometry.py index 1bd843764b..94f135082a 100644 --- a/src/blenderbim/blenderbim/tool/geometry.py +++ b/src/blenderbim/blenderbim/tool/geometry.py @@ -76,11 +76,6 @@ class Geometry(blenderbim.core.tool.Geometry): ifcopenshell.api.run("boundary.remove_boundary", tool.Ifc.get(), boundary=element) return bpy.data.objects.remove(obj) - if element.is_a("IfcElement"): - connections = element.ConnectedTo + element.ConnectedFrom - for connection in connections: - tool.Ifc.get().remove(connection) - collection = obj.BIMObjectProperties.collection if collection: parent = ifcopenshell.util.element.get_aggregate(element) diff --git a/src/ifcopenshell-python/ifcopenshell/api/root/remove_product.py b/src/ifcopenshell-python/ifcopenshell/api/root/remove_product.py index 37206881be..40deb2f0e8 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/root/remove_product.py +++ b/src/ifcopenshell-python/ifcopenshell/api/root/remove_product.py @@ -125,7 +125,11 @@ class Usecase: elif inverse.is_a("IfcRelContainedInSpatialStructure"): if inverse.RelatingStructure == self.settings["product"] or len(inverse.RelatedElements) == 1: self.file.remove(inverse) - elif inverse.is_a("IfcRelConnectsPathElements"): + elif inverse.is_a() in ("IfcRelConnectsElements", "IfcRelConnectsPathElements"): + if inverse.is_a("IfcRelConnectsWithRealizingElements"): + connected_elements = (inverse.RelatingElement, inverse.RelatedElement) + if any(el not in connected_elements for el in inverse.RealizingElements): + continue self.file.remove(inverse) elif inverse.is_a("IfcRelAssignsToGroup"): if len(inverse.RelatedObjects) == 1: diff --git a/src/ifcopenshell-python/test/api/root/test_remove_product.py b/src/ifcopenshell-python/test/api/root/test_remove_product.py index d383859f88..50a50ec805 100644 --- a/src/ifcopenshell-python/test/api/root/test_remove_product.py +++ b/src/ifcopenshell-python/test/api/root/test_remove_product.py @@ -196,6 +196,40 @@ class TestRemoveProduct(test.bootstrap.IFC4): assert len(self.file.by_type("IfcColumn")) == 1 assert len(self.file.by_type("IfcBeam")) == 0 + def test_removing_connection_relationships_of_an_element(self): + element1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall") + element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSlab") + ifcopenshell.api.run( + "geometry.connect_element", + self.file, + related_element=element1, + relating_element=element2, + ) + total_entities = len(list(self.file)) + ifcopenshell.api.run("root.remove_product", self.file, product=element1) + assert len(list(self.file)) == total_entities - 2 + assert len(self.file.by_type("IfcRelConnectsElements")) == 0 + assert len(self.file.by_type("IfcSlab")) == 1 + assert len(self.file.by_type("IfcWall")) == 0 + + def test_removing_connection_relationships_of_an_element_with_additional_realizing_element(self): + element1 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall") + element2 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSlab") + element3 = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcSlab") + self.file.createIfcRelConnectsWithRealizingElements( + ifcopenshell.guid.new(), + OwnerHistory=ifcopenshell.api.run("owner.create_owner_history", self.file), + RelatingElement=element1, + RelatedElement=element2, + RealizingElements=(element1, element2, element3), + ) + total_entities = len(list(self.file)) + ifcopenshell.api.run("root.remove_product", self.file, product=element1) + assert len(list(self.file)) == total_entities - 1 + assert len(self.file.by_type("IfcRelConnectsElements")) == 1 + assert len(self.file.by_type("IfcSlab")) == 2 + assert len(self.file.by_type("IfcWall")) == 0 + def test_removing_all_property_relationships_of_an_element(self): element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall") pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="Foo_Bar")