From 4f77c41bd59f1089fb17cd07f409e52ff21f2db2 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Tue, 24 Jun 2025 18:42:41 +0500 Subject: [PATCH] calculate_unit_scale - small optimization --- src/ifcopenshell-python/ifcopenshell/util/unit.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/util/unit.py b/src/ifcopenshell-python/ifcopenshell/util/unit.py index 6e78d73546..8d2b2d8306 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/unit.py +++ b/src/ifcopenshell-python/ifcopenshell/util/unit.py @@ -697,11 +697,12 @@ def calculate_unit_scale(ifc_file: ifcopenshell.file, unit_type: str = "LENGTHUN unit_scale = 1 unit: ifcopenshell.entity_instance for unit in units.Units: - if not hasattr(unit, "UnitType") or unit.UnitType != unit_type: + if getattr(unit, "UnitType", ...) != unit_type: continue while unit.is_a("IfcConversionBasedUnit"): - unit_scale *= unit.ConversionFactor.ValueComponent.wrappedValue - unit = unit.ConversionFactor.UnitComponent + conversion_factor = unit.ConversionFactor + unit_scale *= conversion_factor.ValueComponent.wrappedValue + unit = conversion_factor.UnitComponent if unit.is_a("IfcSIUnit"): unit_scale *= get_prefix_multiplier(unit.Prefix) return unit_scale