From 102de327377c6502186d58c00b23d45a339e7a0f Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Mon, 17 Mar 2025 15:47:22 +0500 Subject: [PATCH] Fix UI errors in case of uppercase unit names (7af6727) IfcConversionBasedUnit's Name is case insenstive and it was producing UI errors. Noticed working with file from Revit Ryan attached in #6374 Traceback: Traceback (most recent call last): File "\bonsai\bim\module\pset\ui.py", line 456, in poll ObjectMaterialData.load() File "\bonsai\bim\module\material\data.py", line 167, in load cls.data["total_thickness"] = cls.total_thickness() ^^^^^^^^^^^^^^^^^^^^^ File "\bonsai\bim\module\material\data.py", line 331, in total_thickness return format_distance(thickness, precision=precision, suppress_zero_inches=True, in_unit_length=True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "\bonsai\bim\module\drawing\helper.py", line 157, in format_distance unit_length = unit_length_mapping[unit_length] ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^ KeyError: 'FOOT' --- src/bonsai/bonsai/bim/module/drawing/helper.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/drawing/helper.py b/src/bonsai/bonsai/bim/module/drawing/helper.py index ac0b4fbcd8..8c26a17cad 100644 --- a/src/bonsai/bonsai/bim/module/drawing/helper.py +++ b/src/bonsai/bonsai/bim/module/drawing/helper.py @@ -143,12 +143,12 @@ def format_distance( unit_scale = 1 if length_unit := ifcopenshell.util.unit.get_project_unit(tool.Ifc.get(), "LENGTHUNIT"): unit_system = "METRIC" if length_unit.Name == "METRE" else "IMPERIAL" - unit_length = length_unit.Name + unit_length = length_unit.Name.upper() if hasattr(length_unit, "Prefix") and length_unit.Prefix: unit_length = length_unit.Prefix + length_unit.Name unit_length_mapping = { - "foot": "FEET", - "inch": "INCHES", + "FOOT": "FEET", + "INCH": "INCHES", "METRE": "METERS", "DECIMETRE": "DECIMETERS", "CENTIMETRE": "CENTIMETERS",