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'
This commit is contained in:
Andrej730
2025-03-17 15:47:22 +05:00
parent cf3a554b15
commit 102de32737
@@ -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",