diff --git a/src/bonsai/bonsai/tool/spatial.py b/src/bonsai/bonsai/tool/spatial.py index 51224441ed..4a47f94d7e 100644 --- a/src/bonsai/bonsai/tool/spatial.py +++ b/src/bonsai/bonsai/tool/spatial.py @@ -35,6 +35,7 @@ import bonsai.core.tool import bonsai.core.root import bonsai.core.spatial import bonsai.core.geometry +import bonsai.core.unit import bonsai.tool as tool import json from math import pi @@ -452,7 +453,8 @@ class Spatial(bonsai.core.tool.Spatial): new.description = element.Description or "" new.long_name = element.LongName or "" if not element.is_a("IfcProject"): - new["elevation"] = str(ifcopenshell.util.placement.get_storey_elevation(element)) + elevation = ifcopenshell.util.placement.get_storey_elevation(element) + new["elevation"] = tool.Unit.format_value(elevation) new.is_expanded = element.id() not in cls.contracted_containers new.level_index = level_index children = ifcopenshell.util.element.get_parts(element) diff --git a/src/bonsai/bonsai/tool/unit.py b/src/bonsai/bonsai/tool/unit.py index 80be013653..65063c79d2 100644 --- a/src/bonsai/bonsai/tool/unit.py +++ b/src/bonsai/bonsai/tool/unit.py @@ -18,6 +18,7 @@ import bpy import json +import math import ifcopenshell import bonsai.bim.helper import bonsai.core.tool @@ -182,3 +183,13 @@ class Unit(bonsai.core.tool.Unit): precision=4, split_unit=bpy.context.scene.unit_settings.system == "IMPERIAL", ) + + @classmethod + def format_value(cls, value: float) -> str: + precision = tool.Ifc.get().by_type("IfcGeometricRepresentationContext")[0].Precision + if precision: + decimal_places = math.ceil(math.log10(1/precision)) + else: + precision = 1e-5 + decimal_places = 5 + return str(round(precision * round(value / precision), decimal_places))