From 8e29e7cdee51549d0b6b04a314952e83abfd4817 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Tue, 28 Jan 2025 10:46:24 +1100 Subject: [PATCH] Be a bit more forgiving in calculate unit scale to not glitch out on models with no project. It's technically invalid but useful for small snippets. --- src/ifcopenshell-python/ifcopenshell/util/unit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ifcopenshell-python/ifcopenshell/util/unit.py b/src/ifcopenshell-python/ifcopenshell/util/unit.py index 8bdb9e1423..2820592a84 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/unit.py +++ b/src/ifcopenshell-python/ifcopenshell/util/unit.py @@ -692,7 +692,7 @@ def calculate_unit_scale(ifc_file: ifcopenshell.file, unit_type: str = "LENGTHUN :returns: The scale factor """ # Currently we assume that all ifc projects must have IfcProject. - if not (units := ifc_file.by_type("IfcProject")[0].UnitsInContext): + if not (projects := ifc_file.by_type("IfcProject")) or not (units := projects[0].UnitsInContext): return 1 unit_scale = 1 for unit in units.Units: