From 1dfa3f8d797df4ad697c5235dd29eacb76feaf62 Mon Sep 17 00:00:00 2001 From: Manu Varkey Date: Fri, 6 Sep 2024 17:29:25 +0530 Subject: [PATCH] Implement sorting of spacial containers by elevation and name --- src/bonsai/bonsai/tool/spatial.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/bonsai/bonsai/tool/spatial.py b/src/bonsai/bonsai/tool/spatial.py index 6e973cc7cb..f7ff898296 100644 --- a/src/bonsai/bonsai/tool/spatial.py +++ b/src/bonsai/bonsai/tool/spatial.py @@ -452,6 +452,10 @@ class Spatial(bonsai.core.tool.Spatial): new.is_expanded = element.id() not in cls.contracted_containers new.level_index = level_index children = ifcopenshell.util.element.get_parts(element) + if children: + children_elevations = [ifcopenshell.util.placement.get_storey_elevation(el) for el in children] + children_names = [[int(x) if x.isdigit() else x for x in (el.Name or "").split()] for el in children] + children = sorted(children, key=dict(zip(children, tuple(zip(children_elevations, children_names)))).get) new.has_children = bool(children) new.ifc_definition_id = element.id() if new.is_expanded: