diff --git a/src/ifcopenshell-python/ifcopenshell/api/pset/remove_pset.py b/src/ifcopenshell-python/ifcopenshell/api/pset/remove_pset.py index 4b5d3a1503..d923630a90 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/pset/remove_pset.py +++ b/src/ifcopenshell-python/ifcopenshell/api/pset/remove_pset.py @@ -64,7 +64,8 @@ class Usecase: elif self.settings["pset"].is_a() in ("IfcMaterialProperties", "IfcProfileProperties"): properties = self.settings["pset"].Properties or [] for prop in properties: - self.file.remove(prop) + if self.file.get_total_inverses(prop) == 1: + self.file.remove(prop) self.file.remove(self.settings["pset"]) for element in to_purge: self.file.remove(element) diff --git a/src/ifcopenshell-python/test/api/pset/test_remove_pset.py b/src/ifcopenshell-python/test/api/pset/test_remove_pset.py index e06ebf1a86..3ce8d0127e 100644 --- a/src/ifcopenshell-python/test/api/pset/test_remove_pset.py +++ b/src/ifcopenshell-python/test/api/pset/test_remove_pset.py @@ -73,3 +73,13 @@ class TestRemovePset(test.bootstrap.IFC4): assert len(self.file.by_type("IfcRelDefinesByProperties")) == 0 assert len(self.file.by_type("IfcQuantitySet")) == 0 assert len(self.file.by_type("IfcPhysicalSimpleQuantity")) == 0 + + def test_removing_a_pset_with_shared_properties(self): + element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall") + element2 = 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") + pset2 = ifcopenshell.api.run("pset.add_pset", self.file, product=element2, name="Foo_Bar") + ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Foo": "Bar"}) + pset2.HasProperties = pset.HasProperties + ifcopenshell.api.run("pset.remove_pset", self.file, product=element, pset=pset) + assert pset2.HasProperties