Fix #2296. Bug where material and profile psets couldn't be removed.

This commit is contained in:
Dion Moult
2022-07-21 15:12:00 +10:00
parent a11a4032f6
commit a21b73225a
2 changed files with 18 additions and 0 deletions
@@ -41,6 +41,8 @@ class Usecase:
properties = self.settings["pset"].HasProperties or []
elif self.settings["pset"].is_a("IfcQuantitySet"):
properties = self.settings["pset"].Quantities or []
elif self.settings["pset"].is_a() in ("IfcMaterialProperties", "IfcProfileProperties"):
properties = self.settings["pset"].Properties or []
for prop in properties:
self.file.remove(prop)
self.file.remove(self.settings["pset"])
@@ -29,6 +29,22 @@ class TestRemovePset(test.bootstrap.IFC4):
assert len(self.file.by_type("IfcRelDefinesByProperties")) == 0
assert len(self.file.by_type("IfcPropertySet")) == 0
def test_removing_material_psets(self):
element = self.file.createIfcMaterial()
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="Foo_Bar")
assert len(element.HasProperties) == 1
ifcopenshell.api.run("pset.remove_pset", self.file, product=element, pset=pset)
assert len(element.HasProperties) == 0
assert len(self.file.by_type("IfcMaterialProperties")) == 0
def test_removing_profile_psets(self):
element = self.file.createIfcProfileDef()
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="Foo_Bar")
assert len(element.HasProperties) == 1
ifcopenshell.api.run("pset.remove_pset", self.file, product=element, pset=pset)
assert len(element.HasProperties) == 0
assert len(self.file.by_type("IfcMaterialProperties")) == 0
def test_only_unassigning_if_pset_is_used_by_other_elements(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")