diff --git a/src/ifcopenshell-python/ifcopenshell/api/pset/edit_pset.py b/src/ifcopenshell-python/ifcopenshell/api/pset/edit_pset.py index 91d48b3a95..7a73bcaade 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/pset/edit_pset.py +++ b/src/ifcopenshell-python/ifcopenshell/api/pset/edit_pset.py @@ -38,6 +38,8 @@ class Usecase: value = self.settings["properties"][prop.Name] if value is None: prop.NominalValue = None + elif isinstance(value, ifcopenshell.entity_instance): + prop.NominalValue = value else: primary_measure_type = self.get_primary_measure_type(prop.Name, old_value=prop.NominalValue, new_value=value) prop.NominalValue = self.file.create_entity(primary_measure_type, value) 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 d00d5db5aa..4bcd0e354c 100644 --- a/src/ifcopenshell-python/test/api/pset/test_edit_pset.py +++ b/src/ifcopenshell-python/test/api/pset/test_edit_pset.py @@ -124,6 +124,30 @@ class TestEditPset(test.bootstrap.IFC4): assert pset.HasProperties[0].NominalValue.is_a("IfcContextDependentMeasure") assert pset.HasProperties[0].NominalValue.wrappedValue == 34 + def test_editing_properties_with_an_explicit_type(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="Foo_Bar") + ifcopenshell.api.run( + "pset.edit_pset", + self.file, + pset=pset, + properties={ + "MyCustom": self.file.createIfcLabel("True"), + }, + ) + ifcopenshell.api.run( + "pset.edit_pset", + self.file, + pset=pset, + properties={ + "MyCustom": self.file.createIfcBoolean(True), + }, + ) + pset = element.IsDefinedBy[0].RelatingPropertyDefinition + assert pset.HasProperties[0].Name == "MyCustom" + assert pset.HasProperties[0].NominalValue.is_a("IfcBoolean") + assert pset.HasProperties[0].NominalValue.wrappedValue is True + def test_editing_properties_of_non_rooted_elements(self): element = self.file.createIfcMaterial() pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="Foo_Bar")