Title: bim.add_aggregate fragments aggregates when parts are selected · Issue #9588 · IfcOpenShell/IfcOpenShell · GitHub
Open Graph Title: bim.add_aggregate fragments aggregates when parts are selected · Issue #9588 · IfcOpenShell/IfcOpenShell
X Title: bim.add_aggregate fragments aggregates when parts are selected · Issue #9588 · IfcOpenShell/IfcOpenShell
Description: Bug Description bim.add_aggregate corrupts aggregates when the selection includes parts, or spans more than one aggregate. Worst for linked aggregates, where the damage is silent. 1. The new aggregate is parented inside one of the elemen...
Open Graph Description: Bug Description bim.add_aggregate corrupts aggregates when the selection includes parts, or spans more than one aggregate. Worst for linked aggregates, where the damage is silent. 1. The new aggreg...
X Description: Bug Description bim.add_aggregate corrupts aggregates when the selection includes parts, or spans more than one aggregate. Worst for linked aggregates, where the damage is silent. 1. The new aggreg...
Opengraph URL: https://github.com/IfcOpenShell/IfcOpenShell/issues/9588
X: @github
Domain: github.com
IPv4 address: 140.82.112.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"bim.add_aggregate fragments aggregates when parts are selected","articleBody":"### Bug Description\n\n`bim.add_aggregate` corrupts aggregates when the selection includes parts, or spans\nmore than one aggregate. Worst for linked aggregates, where the damage is silent.\n\n**1. The new aggregate is parented inside one of the elements it is collecting**\n\n`BIM_OT_add_aggregate._execute` recomputes the new aggregate's parent on every\niteration of the selection loop:\n\n```python\nfor obj in tool.Blender.get_selected_objects():\n current_aggregate = ifcopenshell.util.element.get_aggregate(element)\n if current_aggregate:\n core.assign_object(..., relating_obj=..., related_obj=aggregate) # new agg -> into this element's parent\n ...\n core.assign_object(..., relating_obj=aggregate, related_obj=obj) # element -> into new agg\n```\n\nWhen parts are selected, a part's `get_aggregate()` is the assembly it belongs to,\nso the new aggregate is parented *inside* the very assembly whose parts it is about\nto take. Whichever selected object is processed last wins, so the damage is\nselection-order dependent.\n\n**2. Selecting a part fragments its aggregate**\n\nEvery selected object is re-parented individually, including parts that should\ntravel with their assembly. For a linked aggregate this silently desynchronises it\nfrom its linked copies.\n\n### Steps to reproduce\n\n1. Create two linked aggregates (duplicate one with `Ctrl+Shift+D`).\n2. Select both empties **and all their parts**.\n3. `bim.add_aggregate()`.\n4. `bim.refresh_linked_aggregate()` -> `StopIteration`.\n\n**Before**\n\n```\n#105 'Default_Name' group=[127] Aggregate_Index 0 +- #72, #89\n#213 'Default_Name_01' group=[127] Aggregate_Index 1 +- #169, #145\n```\n\n**After `bim.add_aggregate()`**\n\n```\n#105 'Default_Name' group=[127] \u003c- still a group member\n +- #271 'Default_Name' group=- pset=None \u003c- NEW wrapper, nested inside #105\n +- #72\n +- #213 'Default_Name_1' group=[127] \u003c- the OTHER member, now inside #105\n | +- #169, #145\n +- #89\n```\n\nTwo group members now nest inside one another, and an ungrouped\n`IfcElementAssembly` sits as a *part* of a group member.\n\n### Consequences\n\n- `RefreshLinkedAggregate.get_original_data` recurses into nested assemblies and\n looks up their `BBIM_Linked_Aggregate` group with a bare `next()`. The ungrouped\n wrapper raises `StopIteration` (reported separately as #9582).\n- `delete_objects` recurses into nested assemblies, so refreshing deletes a member\n nested inside another member - including, for some selections, the base instance,\n which then raises `RuntimeError: An unknown error occurred` from\n `entity_instance.id()`.\n- Once a wrapper has swallowed already-numbered parts, `add_linked_aggregate_pset`\n takes its `index == 0` branch test to mean \"is root\" and writes `{\"Index\": N}`\n with no `Name`/`Aggregate_Index`, which later raises `KeyError: 'Name'`.\n\n### Proposed fix\n\n1. Decide the new aggregate's parent **once**, from the selection, rather than per\n object.\n2. Drop selected elements already contained by another selected element - parts\n travel with their aggregate.\n3. **Promote a selected part to the aggregate that contains it**, so selecting any\n part collects the whole aggregate. This makes the result independent of how\n thoroughly the user selected, and stops anyone unwittingly fragmenting an\n aggregate.\n\nPromotion needs a way to say \"no, I really do want to restructure *inside* this\naggregate\" - which is what aggregate mode already means. So:\n\n> **Not in aggregate mode** -> promote to the outermost enclosing aggregate.\n> **Tabbed into an aggregate** -> no promotion past it; the selected parts are\n> grouped into a sub-assembly, as now.\n\nThis keeps sub-assembly creation, and makes the choice explicit rather than\ninferred. It applies uniformly to linked and plain aggregates - a user should not\nneed to know which kind they have to predict what the operator does.\n\nWith this, selecting one part from each linked aggregate, or both empties plus\nevery part, or any mixture, all produce the same result:\n\n```\n#\u003cnew> group=-\n +- #105 'Default_Name' group=[127] +- #72, #89\n +- #213 'Default_Name_01' group=[127] +- #169, #145\n```\n\n### Behaviour change\n\nOutside aggregate mode, selecting a part of a **plain** aggregate now collects the\nwhole aggregate instead of extracting that part into a nested sub-assembly. The\nexisting scenario `Add aggregate - add a nested aggregate` in\n`src/bonsai/test/bim/feature/aggregate.feature` covers the old behaviour and is\nupdated to tab into the aggregate first. Flagging this explicitly since it is an\nintentional UX change rather than a bug fix.\n\n### Also folded in: #6663\n\n`execute_ifc_duplicate_linked_aggregate_operator` calls\n`tool.Root.recreate_aggregate(old_to_new)` a second time, after\n`execute_ifc_duplicate_operator` already called it via `duplicate_ifc_objects`.\nOn the second run the parent aggregate is still absent from `old_to_new` (it was\nnever duplicated), so `recreate_aggregate` takes its \"parent not found\" branch and\nunassigns the copy from the parent it had just been restored to, stranding it\noutside.\n\nThat blocks the workflow this issue enables: tab into a linked aggregate, create a\nplain sub-assembly, then `bim.duplicate_linked_aggregate_to_3d_cursor()`. The\nsub-assembly is correctly promoted to a linked aggregate and duplicated, but the\ncopy lands outside the wrapper instead of beside its sibling.\n\nRemoving the redundant call is the same fix as PR #8638. It is folded in here\nbecause this issue's workflow depends on it.\n\nFixes #6663.\n\n### Attachments\n\nNone. The reproduction is a new file with two linked aggregates, built by the\nsteps above in a few seconds; the before and after trees are given in full.\n\n### Debug and Error Output\n\n```true\nblender_version: 5.2.1 LTS\nbonsai_version: 0.8.6-alpha260923-8ffab9d\nschema: IFC4\n\nlast_error: Traceback (most recent call last):\n File \"bonsai\\bim\\ifc.py\", line 569, in execute_ifc_operator\n result = getattr(operator, \"_execute\")(context)\n File \"bonsai\\bim\\module\\geometry\\operator.py\", line 2062, in _execute\n element_original_data = get_original_data(element)\n File \"bonsai\\bim\\module\\geometry\\operator.py\", line 1848, in get_original_data\n nested_data = get_original_data(part)\n File \"bonsai\\bim\\module\\geometry\\operator.py\", line 1821, in get_original_data\n group: int = next(\n r.RelatingGroup\n for r in getattr(element, \"HasAssignments\", []) or []\n if r.is_a(\"IfcRelAssignsToGroup\")\n if self.group_name in r.RelatingGroup.Name\n ).id()\nStopIteration\n```\n\n\n","author":{"url":"https://github.com/theoryshaw","@type":"Person","name":"theoryshaw"},"datePublished":"2026-09-24T15:00:33Z","url":"https://github.com/IfcOpenShell/IfcOpenShell/issues/9588"}
| 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:211cf090-1673-8283-f873-f2ae85a9cadb |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8798:2843FB:4462BD:5DB777:6B046F84 |
| html-safe-nonce | 5ebdaf81e398fea2d8025e2340972c0f30c28343ce1724470fa70a2d0d488d0d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4Nzk4OjI4NDNGQjo0NDYyQkQ6NURCNzc3OjZCMDQ2Rjg0IiwidmlzaXRvcl9pZCI6IjQ1NjQ5NzYwMTY0NzUwNTI4NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 3bdae5a25ba39a2d7a1e3fe315a59a50ebd16402c94d127fcf21d67159fc9f56 |
| hovercard-subject-tag | issue:5570299892 |
| 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/9588/issue_layout |
| twitter:image | https://opengraph.githubassets.com/0c6e224b1f52423a5523f6c9367cf7af89cb8233f65d17f4ab247e82280c54e4/IfcOpenShell/IfcOpenShell/issues/9588 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/0c6e224b1f52423a5523f6c9367cf7af89cb8233f65d17f4ab247e82280c54e4/IfcOpenShell/IfcOpenShell/issues/9588 |
| og:image:alt | Bug Description bim.add_aggregate corrupts aggregates when the selection includes parts, or spans more than one aggregate. Worst for linked aggregates, where the damage is silent. 1. The new aggreg... |
| 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 | ae8802492f12d3ba4f6b0d814054e617a2a5616b6327bf8555c10cd5b0dc2a6f |
| 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 | cfb5f24c6e01d85f70804652a5107e5cac03a161 |
| 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