Allowing to add new properties with None values if should_purge is not set to True (and it's False by default)
This commit is contained in:
Andrej730
2024-02-27 17:10:10 +05:00
parent e6691989dc
commit e3a1c29593
2 changed files with 15 additions and 4 deletions
@@ -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
@@ -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):