From 92e519de9e4d2872b0d578a0a02d90d3ca5249cf Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Mon, 20 Sep 2021 14:45:31 +1000 Subject: [PATCH] Be more accommodating when fetching properties to allow for incomplete scripts. --- src/ifcopenshell-python/ifcopenshell/util/element.py | 2 +- src/ifcopenshell-python/test/util/test_element.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/ifcopenshell-python/ifcopenshell/util/element.py b/src/ifcopenshell-python/ifcopenshell/util/element.py index a2167770a2..b5d12a64e8 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/element.py +++ b/src/ifcopenshell-python/ifcopenshell/util/element.py @@ -41,7 +41,7 @@ def get_quantities(quantities): def get_properties(properties): results = {} - for prop in properties: + for prop in properties or []: if prop.is_a("IfcPropertySingleValue"): results[prop.Name] = prop.NominalValue.wrappedValue if prop.NominalValue else None elif prop.is_a("IfcComplexProperty"): diff --git a/src/ifcopenshell-python/test/util/test_element.py b/src/ifcopenshell-python/test/util/test_element.py index f2c1dd5f33..ec0a40984b 100644 --- a/src/ifcopenshell-python/test/util/test_element.py +++ b/src/ifcopenshell-python/test/util/test_element.py @@ -51,6 +51,11 @@ class TestGetQuantitiesIFC4(test.bootstrap.IFC4): class TestGetPropertiesIFC4(test.bootstrap.IFC4): + def test_getting_no_properties_when_none_are_available(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="name") + assert ifcopenshell.util.element.get_properties(pset.HasProperties) == {} + def test_getting_single_properties_from_a_list_of_properties(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="name")