From 3da718a6d10c170a343a0ece2323d925ff65bfee Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Sun, 19 Mar 2023 15:17:26 +1100 Subject: [PATCH] Fix bug where removing objects could leave orphaned annotation relationships --- .../ifcopenshell/api/root/remove_product.py | 5 +++++ .../test/api/root/test_remove_product.py | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/src/ifcopenshell-python/ifcopenshell/api/root/remove_product.py b/src/ifcopenshell-python/ifcopenshell/api/root/remove_product.py index af10d9b149..0e876b0c47 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/root/remove_product.py +++ b/src/ifcopenshell-python/ifcopenshell/api/root/remove_product.py @@ -130,4 +130,9 @@ class Usecase: elif inverse.is_a("IfcRelAssignsToGroup"): if len(inverse.RelatedObjects) == 1: self.file.remove(inverse) + elif inverse.is_a("IfcRelAssignsToProduct"): + if inverse.RelatingProduct == self.settings["product"]: + self.file.remove(inverse) + elif len(inverse.RelatedObject) == 1: + self.file.remove(inverse) self.file.remove(self.settings["product"]) 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 c66ab9686b..d383859f88 100644 --- a/src/ifcopenshell-python/test/api/root/test_remove_product.py +++ b/src/ifcopenshell-python/test/api/root/test_remove_product.py @@ -245,3 +245,10 @@ class TestRemoveProduct(test.bootstrap.IFC4): ifcopenshell.api.run("group.assign_group", self.file, products=[element], group=group) ifcopenshell.api.run("root.remove_product", self.file, product=element) assert not self.file.by_type("IfcRelAssignsToGroup") + + def test_removing_product_assignments(self): + element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall") + annotation = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcAnnotation") + ifcopenshell.api.run("drawing.assign_product", self.file, relating_product=element, related_object=annotation) + ifcopenshell.api.run("root.remove_product", self.file, product=element) + assert not self.file.by_type("IfcRelAssignsToProduct")