Title: Bonsai: editing one window deletes (or resizes) the opening of another occurrence of the same type (`update_simple_openings`) · Issue #9591 · IfcOpenShell/IfcOpenShell · GitHub
Open Graph Title: Bonsai: editing one window deletes (or resizes) the opening of another occurrence of the same type (`update_simple_openings`) · Issue #9591 · IfcOpenShell/IfcOpenShell
X Title: Bonsai: editing one window deletes (or resizes) the opening of another occurrence of the same type (`update_simple_openings`) · Issue #9591 · IfcOpenShell/IfcOpenShell
Description: Related: #9353 (OverallWidth/Height written to all occurrences), #9406 (fix for the attribute path only). Version: Bonsai 0.8.5 / IfcOpenShell 0.8.5, Blender 5.2.1 LTS, Windows. Geometry library opencascade (same with the default). Setup...
Open Graph Description: Related: #9353 (OverallWidth/Height written to all occurrences), #9406 (fix for the attribute path only). Version: Bonsai 0.8.5 / IfcOpenShell 0.8.5, Blender 5.2.1 LTS, Windows. Geometry library op...
X Description: Related: #9353 (OverallWidth/Height written to all occurrences), #9406 (fix for the attribute path only). Version: Bonsai 0.8.5 / IfcOpenShell 0.8.5, Blender 5.2.1 LTS, Windows. Geometry library op...
Opengraph URL: https://github.com/IfcOpenShell/IfcOpenShell/issues/9591
X: @github
Domain: github.com
IPv4 address: 140.82.112.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Bonsai: editing one window deletes (or resizes) the opening of another occurrence of the same type (`update_simple_openings`)","articleBody":"Related: #9353 (OverallWidth/Height written to all occurrences), #9406 (fix for the attribute path only).\n\n**Version:** Bonsai 0.8.5 / IfcOpenShell 0.8.5, Blender 5.2.1 LTS, Windows. Geometry library `opencascade` (same with the default).\n\n## Setup (empty project, built with `repro_build.py` below)\n- One `IfcWall` (6.0 × 0.3 × 3.0 m, layer set AXIS2).\n- One `IfcWindowType` \"Universal\" with a Body `RepresentationMap`.\n- Two `IfcWindow`s of that type, each with **its own** body (`add_window_representation`), **its own** `IfcOpeningElement` (SweptSolid box, not mapped) and a `BBIM_Window` pset. The type was assigned with `should_map_representations=False`.\n - FENS-A 1.00 × 1.20 at x = 1.0\n - FENS-B 0.60 × 0.80 at x = 3.5\n\n## Steps\n1. Load the file in Bonsai.\n2. Select FENS-B → Edit window (`bim.enable_editing_window`) → Overall Width 0.60 → 0.70 → `bim.finish_editing_window`.\n3. Save, then run `repro_meas.py` on the file before and after.\n\n## Result\n| | before | after |\n|---|---|---|\n| FENS-A OverallWidth/Height | 1.000 / 1.200 | **0.700 / 0.800** (#9353) |\n| FENS-A body | 1.000 × 1.200 | 1.000 × 1.200 (unchanged) |\n| FENS-A opening representation | Body SweptSolid, 1.000 × 1.200 | **none, the opening has no representation** |\n| FENS-B OverallWidth/Height | 0.600 / 0.800 | 0.700 / 0.800 |\n| FENS-B body | 0.600 × 0.800 | 0.700 × 0.800 |\n| FENS-B opening | 0.600 × 0.800 | **0.600 × 0.800, not updated** |\n\n## Expected\nOnly FENS-B and its own opening change. FENS-A's opening is untouched.\n\n## Cause (source, `bonsai/tool/model.py`, `Model.update_simple_openings`)\n- The function iterates over **all occurrences of the type** and rebuilds the opening of the **first occurrence that has `FillsVoids`**, which is not necessarily the edited element. It uses that sibling's filling and wall (`has_replaced_opening_representation`), so the edited element's own opening is never regenerated.\n- `unassign_representation(product=opening, representation=old)` runs **before** `for inverse in ifc_file.get_inverse(old_representation): replace_attribute(...)`. After the unassign, a non-mapped representation has no inverses left, so the new representation is attached nowhere and `remove_representation(old)` leaves the sibling's opening empty.\n- If the sibling's opening is a `MappedRepresentation`, the resolved source inside the `IfcRepresentationMap` is replaced instead, so the sibling's opening is resized to the edited element's dimensions. Observed in a production model: a door opening grew to 0.985 × 2.135 while its door stayed 0.885 × 2.01.\n- The trailing `bpy.ops.bim.recalculate_fill()` on all fillings then sets every sibling's opening placement to its filling's matrix. Openings that are intentionally offset (below finished floor level, roof windows with a rotated placement) move or rotate. Observed: 70 mm vertical shift on doors, a 90° rotation on a roof-window opening, about 7 m displacement on one window opening.\n- Variant without a `RepresentationMap` on the type: `update_simple_openings` aborts with `filling_body=None`; sibling openings survive, but the edited element's opening is still not updated.\n\n## Suggested fix\nScope the opening update to the edited element, mirroring #9406: regenerate only the opening(s) of fillings whose Body resolves to the representation the modifier just rebuilt (shared type map), otherwise only the edited element's own opening. Resolve the inverses of the old representation **before** unassigning it. Call `recalculate_fill` only for the fillings whose opening was actually regenerated.\n\n\u003cdetails>\u003csummary>\u003ccode>repro_build.py\u003c/code>\u003c/summary>\n\n```python\n# Minimal reproduction: update_simple_openings overwrites the own opening of a type sibling\n# usage: python repro_build.py repro.ifc\nimport sys, json\nimport numpy as np\nimport ifcopenshell\nimport ifcopenshell.api as api\nimport ifcopenshell.api.root, ifcopenshell.api.unit, ifcopenshell.api.context, ifcopenshell.api.aggregate, ifcopenshell.api.geometry, ifcopenshell.api.material, ifcopenshell.api.type, ifcopenshell.api.spatial, ifcopenshell.api.pset, ifcopenshell.api.feature\nimport ifcopenshell.util.shape_builder as sb\n\nf = ifcopenshell.file(schema=\"IFC4X3\")\nproj = api.root.create_entity(f, ifc_class=\"IfcProject\", name=\"Repro\")\napi.unit.assign_unit(f, length={\"is_metric\": True, \"raw\": \"METERS\"})\nmodel = api.context.add_context(f, context_type=\"Model\")\nbody = api.context.add_context(f, context_type=\"Model\", context_identifier=\"Body\", target_view=\"MODEL_VIEW\", parent=model)\nsite = api.root.create_entity(f, ifc_class=\"IfcSite\", name=\"Site\")\nbldg = api.root.create_entity(f, ifc_class=\"IfcBuilding\", name=\"Building\")\nst = api.root.create_entity(f, ifc_class=\"IfcBuildingStorey\", name=\"Storey\")\napi.aggregate.assign_object(f, relating_object=proj, products=[site])\napi.aggregate.assign_object(f, relating_object=site, products=[bldg])\napi.aggregate.assign_object(f, relating_object=bldg, products=[st])\nfor e in (site, bldg, st):\n api.geometry.edit_object_placement(f, product=e)\n\n# Wall 6 m x 0.3 m x 3 m, layer set AXIS2\nmat = api.material.add_material(f, name=\"Masonry\")\nls = api.material.add_material_set(f, name=\"W300\", set_type=\"IfcMaterialLayerSet\")\napi.material.add_layer(f, layer_set=ls, material=mat).LayerThickness = 0.3\nwt = api.root.create_entity(f, ifc_class=\"IfcWallType\", name=\"W300\")\napi.material.assign_material(f, products=[wt], material=ls)\nwall = api.root.create_entity(f, ifc_class=\"IfcWall\", name=\"WALL\")\napi.type.assign_type(f, related_objects=[wall], relating_type=wt)\napi.geometry.edit_object_placement(f, product=wall)\napi.spatial.assign_container(f, relating_structure=st, products=[wall])\nwrep = api.geometry.add_wall_representation(f, context=body, length=6.0, height=3.0, thickness=0.3)\napi.geometry.assign_representation(f, product=wall, representation=wrep)\n\n# Window type with a Body map (1.00 x 1.20)\nLIN = {\"LiningDepth\": 0.06, \"LiningThickness\": 0.06, \"LiningOffset\": 0.0, \"LiningToPanelOffsetX\": 0.025, \"LiningToPanelOffsetY\": 0.025}\nPAN = [{\"FrameDepth\": 0.035, \"FrameThickness\": 0.035}]\nwtype = api.root.create_entity(f, ifc_class=\"IfcWindowType\", name=\"Universal\", predefined_type=\"WINDOW\")\ntrep = api.geometry.add_window_representation(f, context=body, overall_height=1.2, overall_width=1.0, partition_type=\"SINGLE_PANEL\", lining_properties=LIN, panel_properties=PAN)\napi.geometry.assign_representation(f, product=wtype, representation=trep)\n\ndef window(name, x, W, H, sill=0.9):\n w = api.root.create_entity(f, ifc_class=\"IfcWindow\", name=name)\n api.spatial.assign_container(f, relating_structure=st, products=[w])\n M = np.eye(4); M[:3, 3] = [x, 0.0, sill] # outer face of the wall at y=0, lining towards +y\n api.geometry.edit_object_placement(f, product=w, matrix=M)\n r = api.geometry.add_window_representation(f, context=body, overall_height=H, overall_width=W, partition_type=\"SINGLE_PANEL\", lining_properties=LIN, panel_properties=PAN)\n w.Representation = f.createIfcProductDefinitionShape(Representations=[r]) # own geometry, not via the type\n w.OverallWidth, w.OverallHeight = W, H\n data = {\"window_type\": \"SINGLE_PANEL\", \"overall_height\": H, \"overall_width\": W,\n \"lining_properties\": {\"lining_depth\": .06, \"lining_thickness\": .06, \"lining_offset\": 0.0, \"lining_to_panel_offset_x\": .025, \"lining_to_panel_offset_y\": .025},\n \"panel_properties\": {\"frame_depth\": [.035, .035, .035], \"frame_thickness\": [.035, .035, .035]}}\n api.pset.edit_pset(f, pset=api.pset.add_pset(f, product=w, name=\"BBIM_Window\"), properties={\"Data\": json.dumps(data)})\n # own opening, box W x 1.2 x H, centred over the wall (y -0.45..0.75)\n op = api.root.create_entity(f, ifc_class=\"IfcOpeningElement\", name=name + \"-OPENING\")\n api.geometry.edit_object_placement(f, product=op, matrix=M)\n b = sb.ShapeBuilder(f)\n prof = b.rectangle(size=np.array([W, 1.2]), position=np.array([0.0, -0.45]))\n solid = b.extrude(prof, magnitude=H, position=np.array([0.0, 0.0, 0.0]))\n api.geometry.assign_representation(f, product=op, representation=b.get_representation(body, [solid]))\n api.feature.add_feature(f, feature=op, element=wall)\n api.feature.add_filling(f, opening=op, element=w)\n return w\n\nw1 = window(\"FENS-A\", 1.0, 1.00, 1.20)\nw2 = window(\"FENS-B\", 3.5, 0.60, 0.80)\napi.type.assign_type(f, related_objects=[w1, w2], relating_type=wtype, should_map_representations=False)\nf.write(sys.argv[1]); print(\"ok\", sys.argv[1])\n```\n\u003c/details>\n\n\u003cdetails>\u003csummary>\u003ccode>repro_meas.py\u003c/code>\u003c/summary>\n\n```python\n# usage: python repro_meas.py before.ifc after.ifc\nimport sys\nimport numpy as np\nimport ifcopenshell, ifcopenshell.geom\nimport ifcopenshell.util.placement as up\n\nS = ifcopenshell.geom.settings()\n\ndef bb(p, rep):\n try:\n shape = ifcopenshell.geom.create_shape(S, rep) # keep a reference while reading verts\n v = np.array(shape.verts, dtype=float).reshape(-1, 3).copy()\n except Exception as e:\n return \"ERR \" + str(e)[:40]\n M = up.get_local_placement(p.ObjectPlacement)\n w = (M @ np.c_[v, np.ones(len(v))].T).T[:, :3]\n mn, mx = w.min(0), w.max(0)\n return f\"x {mn[0]:.3f}..{mx[0]:.3f} (w {mx[0]-mn[0]:.3f}) z {mn[2]:.3f}..{mx[2]:.3f} (h {mx[2]-mn[2]:.3f})\"\n\nfor fn in sys.argv[1:]:\n f = ifcopenshell.open(fn); print(\"==\", fn)\n for w in sorted(f.by_type(\"IfcWindow\"), key=lambda e: e.Name):\n op = w.FillsVoids[0].RelatingOpeningElement\n wr = [r for r in w.Representation.Representations if r.RepresentationIdentifier == \"Body\"]\n orr = op.Representation.Representations if op.Representation else []\n print(f\" {w.Name}: OverallWidth/Height {w.OverallWidth:.3f}/{w.OverallHeight:.3f} | window {bb(w, wr[0]) if wr else None}\")\n print(f\" opening {op.Name}: reps {[(r.id(), r.RepresentationIdentifier, r.RepresentationType) for r in orr]} | {bb(op, orr[0]) if orr else 'NO GEOMETRY'}\")\n```\n\u003c/details>\n","author":{"url":"https://github.com/M-H-H-B","@type":"Person","name":"M-H-H-B"},"datePublished":"2026-09-24T18:43:21Z","url":"https://github.com/IfcOpenShell/IfcOpenShell/issues/9591"}
| 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:489aa8cc-dc3d-fe6f-d129-11b3b3130b55 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8CD6:2ACC63:10BCDD:164EBA:6B04B113 |
| html-safe-nonce | cb100b02e615c018ae248fc6bceebb4a4321719fde3606ba1229c256da86ebe3 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4Q0Q2OjJBQ0M2MzoxMEJDREQ6MTY0RUJBOjZCMDRCMTEzIiwidmlzaXRvcl9pZCI6IjgxMDcxODI0OTg4MTMwOTYyMTEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 428a6de448614745678159e136b66fd75f49191583ae6e22929e087c4caf4067 |
| hovercard-subject-tag | issue:5572933689 |
| 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/9591/issue_layout |
| twitter:image | https://opengraph.githubassets.com/253c8e5df58d6e69b1971cf2ecac687981a5800ed0b7e07661d9b24050113ba9/IfcOpenShell/IfcOpenShell/issues/9591 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/253c8e5df58d6e69b1971cf2ecac687981a5800ed0b7e07661d9b24050113ba9/IfcOpenShell/IfcOpenShell/issues/9591 |
| og:image:alt | Related: #9353 (OverallWidth/Height written to all occurrences), #9406 (fix for the attribute path only). Version: Bonsai 0.8.5 / IfcOpenShell 0.8.5, Blender 5.2.1 LTS, Windows. Geometry library op... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | M-H-H-B |
| hostname | github.com |
| expected-hostname | github.com |
| None | f1d110ea058a0915c1d8aa3fc2069fa15801e128f591e5762525abe77490ecb1 |
| 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 | ffa22a65e4c46d376940fe34b05e6a7e9c7fdb9b |
| 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