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.
This commit is contained in:
Dion Moult
2025-01-28 10:46:24 +11:00
parent 6e0954e855
commit 8e29e7cdee
@@ -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: