diff --git a/src/ifcopenshell-python/ifcopenshell/api/pset/edit_pset.py b/src/ifcopenshell-python/ifcopenshell/api/pset/edit_pset.py index 58a453e774..81b57db874 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/pset/edit_pset.py +++ b/src/ifcopenshell-python/ifcopenshell/api/pset/edit_pset.py @@ -278,7 +278,7 @@ class Usecase: def add_new_properties(self): properties = [] for name, value in self.settings["properties"].items(): - if value is None: + if value is None and self.settings["should_purge"]: continue unit, value = self.unpack_unit_value(value) @@ -343,8 +343,11 @@ class Usecase: else: primary_measure_type = self.get_primary_measure_type(name, new_value=value) - value = self.cast_value_to_primary_measure_type(value, primary_measure_type) - nominal_value = self.file.create_entity(primary_measure_type, value) + if value is None: + nominal_value = value + else: + value = self.cast_value_to_primary_measure_type(value, primary_measure_type) + nominal_value = self.file.create_entity(primary_measure_type, value) args = {"Name": name, "NominalValue": nominal_value} if unit: args["Unit"] = unit diff --git a/src/ifcopenshell-python/test/api/pset/test_edit_pset.py b/src/ifcopenshell-python/test/api/pset/test_edit_pset.py index d7c8fdf025..d7c0db240e 100644 --- a/src/ifcopenshell-python/test/api/pset/test_edit_pset.py +++ b/src/ifcopenshell-python/test/api/pset/test_edit_pset.py @@ -84,11 +84,19 @@ class TestEditPset(test.bootstrap.IFC4): assert pset.HasProperties[0].NominalValue.is_a("IfcThermalTransmittanceMeasure") assert pset.HasProperties[0].NominalValue.wrappedValue == 42 - def test_not_adding_a_property_if_it_is_none(self): + def test_adding_a_property_if_it_is_none(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="Pset_WallCommon") + # should_purge is false by default ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Reference": None}) pset = element.IsDefinedBy[0].RelatingPropertyDefinition + assert len(pset.HasProperties) == 1 + + def test_not_adding_a_property_if_it_is_none_and_should_purge_is_true(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="Pset_WallCommon") + ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Reference": None}, should_purge=True) + pset = element.IsDefinedBy[0].RelatingPropertyDefinition assert len(pset.HasProperties) == 0 def test_removing_a_none_property_if_specified(self):