mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-18 22:33:33 +00:00
Bonsai: fix KeyError in format_distance for kilometre and mile units #8255
The project-unit to Blender-unit mapping in format_distance only knew
FOOT/INCH/METRE/DECIMETRE/CENTIMETRE/MILLIMETRE, so creating a project
with Kilometers or Miles in the New Project Wizard crashed with
KeyError: 'KILOMETRE' (or 'MILE') as soon as the spatial tree formatted
an elevation. Add the missing Blender-supported units (kilometre, mile,
micrometre) and fall through gracefully for anything else (for example
HECTOMETRE) so unknown units use the adaptive formatting branch instead
of raising.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
(cherry picked from commit 980988f208)
This commit is contained in:
committed by
Dion Moult
parent
6d0809c703
commit
bda66c9ec2
@@ -189,14 +189,20 @@ def format_distance(
|
|||||||
if hasattr(length_unit, "Prefix") and length_unit.Prefix:
|
if hasattr(length_unit, "Prefix") and length_unit.Prefix:
|
||||||
unit_length = length_unit.Prefix + length_unit.Name
|
unit_length = length_unit.Prefix + length_unit.Name
|
||||||
unit_length_mapping = {
|
unit_length_mapping = {
|
||||||
|
"MILE": "MILES",
|
||||||
"FOOT": "FEET",
|
"FOOT": "FEET",
|
||||||
"INCH": "INCHES",
|
"INCH": "INCHES",
|
||||||
|
"KILOMETRE": "KILOMETERS",
|
||||||
"METRE": "METERS",
|
"METRE": "METERS",
|
||||||
"DECIMETRE": "DECIMETERS",
|
"DECIMETRE": "DECIMETERS",
|
||||||
"CENTIMETRE": "CENTIMETERS",
|
"CENTIMETRE": "CENTIMETERS",
|
||||||
"MILLIMETRE": "MILLIMETERS",
|
"MILLIMETRE": "MILLIMETERS",
|
||||||
|
"MICROMETRE": "MICROMETERS",
|
||||||
}
|
}
|
||||||
unit_length = unit_length_mapping[unit_length]
|
# Fall through for units without a dedicated formatter (e.g.
|
||||||
|
# HECTOMETRE) so they use the adaptive branch instead of a
|
||||||
|
# KeyError (#8255).
|
||||||
|
unit_length = unit_length_mapping.get(unit_length, unit_length)
|
||||||
# For now we only format area in IFC Units
|
# For now we only format area in IFC Units
|
||||||
if area_unit := ifcopenshell.util.unit.get_project_unit(tool.Ifc.get(), "AREAUNIT"):
|
if area_unit := ifcopenshell.util.unit.get_project_unit(tool.Ifc.get(), "AREAUNIT"):
|
||||||
area_unit_symbol = " " + ifcopenshell.util.unit.get_unit_symbol(area_unit)
|
area_unit_symbol = " " + ifcopenshell.util.unit.get_unit_symbol(area_unit)
|
||||||
|
|||||||
Reference in New Issue
Block a user