From 292cbf55adfb190896633b939cebf906ab98a322 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Wed, 13 Oct 2021 12:17:20 +1100 Subject: [PATCH] Resolve #1773. IfcCSV now supports editing properties that were previously null. --- src/ifccsv/ifccsv.py | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/ifccsv/ifccsv.py b/src/ifccsv/ifccsv.py index 5106d5c7c2..f1ced2f432 100755 --- a/src/ifccsv/ifccsv.py +++ b/src/ifccsv/ifccsv.py @@ -47,7 +47,7 @@ class IfcAttributeSetter: pset_name, prop = key.split(".", 1) pset = IfcAttributeSetter.get_element_pset(element, pset_name) if pset: - IfcAttributeSetter.set_pset_property(pset, prop, value) + IfcAttributeSetter.set_pset_property(ifc_file, pset, prop, value) return element return element @@ -85,11 +85,27 @@ class IfcAttributeSetter: return relationship.RelatingPropertyDefinition @staticmethod - def set_pset_property(pset, name, value): + def set_pset_property(ifc_file, pset, name, value): for property in pset.HasProperties: - if property.Name == name: - # In lieu of loading a map for data casting, we only have four - # options, which this ugly method will determine. + if property.Name != name: + continue + + # In lieu of loading a map for data casting, we only have four + # options, which this ugly method will determine. + if property.NominalValue is None: + if value.isnumeric(): + property.NominalValue = ifc_file.createIfcInteger(int(value)) + elif value.lower() in ["1", "true", "yes", "uh-huh"]: + property.NominalValue = ifc_file.createIfcBoolean(True) + elif value.lower() in ["0", "false", "no", "nope"]: + property.NominalValue = ifc_file.createIfcBoolean(False) + else: + try: + value = float(value) + property.NominalValue = ifc_file.createIfcReal(value) + except: + property.NominalValue = ifc_file.createIfcLabel(str(value)) + else: try: property.NominalValue.wrappedValue = str(value) except: @@ -100,7 +116,7 @@ class IfcAttributeSetter: property.NominalValue.wrappedValue = int(value) except: property.NominalValue.wrappedValue = ( - True if value.lower() in ["1", "t", "true", "yes", "y", "uh-huh"] else False + True if value.lower() in ["1", "true", "yes", "uh-huh"] else False )