Title: Bonsai: storey elevations intermittently reset to 0 (spatial decomposition re-import triggers update_elevation) · Issue #8545 · IfcOpenShell/IfcOpenShell · GitHub
Open Graph Title: Bonsai: storey elevations intermittently reset to 0 (spatial decomposition re-import triggers update_elevation) · Issue #8545 · IfcOpenShell/IfcOpenShell
X Title: Bonsai: storey elevations intermittently reset to 0 (spatial decomposition re-import triggers update_elevation) · Issue #8545 · IfcOpenShell/IfcOpenShell
Description: Description Every so often, all storeys in a model have their elevation reset to 0 — the storey empties get moved to Z = 0 and the container manager (Spatial Decomposition panel) shows an elevation of 0 for every level. There is no expli...
Open Graph Description: Description Every so often, all storeys in a model have their elevation reset to 0 — the storey empties get moved to Z = 0 and the container manager (Spatial Decomposition panel) shows an elevation...
X Description: Description Every so often, all storeys in a model have their elevation reset to 0 — the storey empties get moved to Z = 0 and the container manager (Spatial Decomposition panel) shows an elevation...
Opengraph URL: https://github.com/IfcOpenShell/IfcOpenShell/issues/8545
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Bonsai: storey elevations intermittently reset to 0 (spatial decomposition re-import triggers update_elevation)","articleBody":"## Description\n\nEvery so often, all storeys in a model have their elevation reset to `0` — the storey empties get moved to `Z = 0` and the container manager (Spatial Decomposition panel) shows an elevation of 0 for every level. There is no explicit user action that causes it; it happens intermittently during normal editing.\n\n## Root cause\n\nThe `elevation` field of `BIMContainer` is a `StringProperty` with an `update=update_elevation` callback. That callback **writes to the IFC model** — it moves the storey object's Z placement:\n\n```python\n# src/bonsai/bonsai/bim/module/spatial/prop.py\nobj.matrix_world[2][3] = elevation\nbonsai.core.geometry.edit_object_placement(...)\n```\n\nThe problem is that this callback fires not only on genuine UI edits, but also **every time the spatial decomposition list is rebuilt in code**. In `Spatial.import_spatial_element` the elevation is assigned by attribute:\n\n```python\n# src/bonsai/bonsai/tool/spatial.py\nnew[\"name\"] = element.Name or \"Unnamed\" # subscript -> BYPASSES update_name\n...\nnew.long_name = element.LongName or \"\" # attribute -> TRIGGERS update_long_name\nnew.elevation = tool.Unit.format_distance(...) # attribute -> TRIGGERS update_elevation\n```\n\n`name` is deliberately set with subscript (`new[\"name\"] = ...`) specifically to avoid triggering its update callback, but `elevation` (and `long_name`) use plain attribute assignment, so their callbacks fire on every re-import.\n\n`import_spatial_decomposition` runs constantly — after editing any element's attributes, after geometry edits, aggregate changes, container expand/contract, project load, etc. So on essentially every rebuild, every storey's elevation is round-tripped: IFC elevation → `format_distance` → string → `update_elevation` → `parse_distance_string` → back into the IFC placement.\n\nTwo failure modes result:\n\n1. **Silent drift** — `format_distance` rounds to 1/256\", so elevations can slowly shift on every rebuild.\n2. **Collapse to 0** — if `parse_distance_string` fails, `update_elevation` falls into its fallback branch and writes `0`:\n\n ```python\n except Exception:\n elevation = 0 # then obj.matrix_world[2][3] = 0 for EVERY storey\n ```\n\n### Why it's intermittent\n\n`format_distance` chooses its unit system from the **IFC project unit**, but `parse_distance_string` chooses its grammar from the **Blender scene unit** (`bpy.context.scene.unit_settings.system`):\n\n```python\n# src/bonsai/bonsai/tool/unit.py\nif bpy.context.scene.unit_settings.system == \"IMPERIAL\":\n primary_parser = Lark(grammar_imperial)\n fallback_parser = Lark(grammar_metric)\nelse:\n ...\n```\n\nWhen the Blender scene unit and the IFC project unit get out of sync (or a formatted string trips both the primary and fallback grammar), the parse returns `(False, 0.0)`, `float(...)` on the formatted string raises, and every storey is moved to `Z = 0` in a single re-import pass. That matches the \"every so often, all storeys back to 0\" symptom.\n\n## Affected code\n\n- `src/bonsai/bonsai/bim/module/spatial/prop.py` — `update_elevation` (write-to-IFC callback + silent `0` fallback)\n- `src/bonsai/bonsai/tool/spatial.py` — `import_spatial_element` (`new.elevation = ...` attribute assignment triggers the callback on every import)\n- `src/bonsai/bonsai/tool/unit.py` — `parse_distance_string` (grammar chosen from Blender scene unit, not IFC project unit)\n\n## Proposed fix\n\n1. Assign elevation (and `long_name`) via subscript during import so the callback does not fire on programmatic rebuilds: `new[\"elevation\"] = ...`, matching the existing `new[\"name\"]` idiom.\n2. Harden `update_elevation` so a parse failure never silently writes `0` — bail out instead of moving the object.\n3. (Longer term) Make `parse_distance_string` use the IFC project unit like `format_distance`, so the round-trip is symmetric.\n\n## Environment\n\n- Bonsai, branch `v0.8.0`\n\n---\n\nIntended to be fixed alongside #8344, which already touches `import_spatial_decomposition` in the same subsystem (storey placement sync on Load Spatial Structure).\n","author":{"url":"https://github.com/theoryshaw","@type":"Person","name":"theoryshaw"},"datePublished":"2026-07-12T14:20:53Z","url":"https://github.com/IfcOpenShell/IfcOpenShell/issues/8545"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:7525779d-09cc-25f8-99b4-f3e8bbc2083c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CA24:38F59A:7D7193:A96837:6B04A9CE |
| html-safe-nonce | de64e05bc55dcbdd443d6d510db2843bad5854990152e8ce49e1da4810585019 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQTI0OjM4RjU5QTo3RDcxOTM6QTk2ODM3OjZCMDRBOUNFIiwidmlzaXRvcl9pZCI6IjU0MDY4MzA5NTA4NjcwNTMwMDYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | d0bd28571763ca5cd1f647f60a361f2a34e0338ed3035f077442f462227ab6d5 |
| hovercard-subject-tag | issue:4867386641 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/IfcOpenShell/IfcOpenShell/8545/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8b961dc222a1cd1aedc54183341c115e8af98cf1641e6f85417ca492ef28e21f/IfcOpenShell/IfcOpenShell/issues/8545 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8b961dc222a1cd1aedc54183341c115e8af98cf1641e6f85417ca492ef28e21f/IfcOpenShell/IfcOpenShell/issues/8545 |
| og:image:alt | Description Every so often, all storeys in a model have their elevation reset to 0 — the storey empties get moved to Z = 0 and the container manager (Spatial Decomposition panel) shows an elevation... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | theoryshaw |
| hostname | github.com |
| expected-hostname | github.com |
| None | 188497a0f45a7aa8f7c866faa1950d1a7f8d82b59416adf549b222ad1d1dd19b |
| turbo-cache-control | no-preview |
| go-import | github.com/IfcOpenShell/IfcOpenShell git https://github.com/IfcOpenShell/IfcOpenShell.git |
| octolytics-dimension-user_id | 13692563 |
| octolytics-dimension-user_login | IfcOpenShell |
| octolytics-dimension-repository_id | 40473201 |
| octolytics-dimension-repository_nwo | IfcOpenShell/IfcOpenShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 40473201 |
| octolytics-dimension-repository_network_root_nwo | IfcOpenShell/IfcOpenShell |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 557cfbac6cdb532730c95c90f2cefdc0c4128029 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width