You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Representation Items panel stores its item list in the .blend, but never checks that the ids are still valid against the loaded IFC. After a .blend/.ifc round trip (open the .blend, which reloads the .ifc next to it) the list can be replayed against a different state of the file, and the first button that touches an item raises:
Python: Traceback (most recent call last):
File "...\bonsai\tool\ifc.py", line 367, in execute
IfcStore.execute_ifc_operator(self, context)
File "...\bonsai\bim\ifc.py", line 569, in execute_ifc_operator
result = getattr(operator, "_execute")(context)
File "...\bonsai\bim\module\geometry\operator.py", line 3586, in _execute
representation_item = ifc_file.by_id(representation_item_id)
File "...\ifcopenshell\file.py", line 836, in by_id
return self[id]
File "...\ifcopenshell\file.py", line 823, in __getitem__
return entity_instance(self.wrapped_data.by_id(key), self)
File "...\ifcopenshell\ifcopenshell_wrapper.py", line 5826, in by_id
return _ifcopenshell_wrapper.file_by_id(self, id)
RuntimeError: Instance #1937489 not found
Opening the same .ifc directly (no .blend) does not produce the error - the list is then rebuilt from the file that was just loaded, so every id resolves.
Cause
BIMObjectGeometryProperties.items is a CollectionProperty on the object (bim/module/geometry/prop.py), so is_editing and every items[].ifc_definition_id are written into the .blend. EnableEditingRepresentationItems is the only thing that rebuilds them. Nothing invalidates that list when the IFC is (re)loaded, so a list captured in one session can outlive the instances it points at, and the operators then call by_id() on a dead id with no guard.
Affected call sites
All on v0.9.0 (checked at e18d927), src/bonsai/bonsai/bim/module/geometry/operator.py:
line
operator
3275
RemoveRepresentationItem
3301
SelectRepresentationItem
3370
EnableEditingRepresentationItemStyle (the traceback above)
3396
EditRepresentationItemStyle
3522
EditRepresentationItemShapeAspect
3595
RemoveRepresentationItemFromShapeAspect
4200
EditRepresentationItemLayer
4228
UnassignRepresentationItemLayer
UnassignRepresentationItemStyle already resolves through tool.Ifc.get_entity_by_id and reports instead of raising, but it leaves the stale list in place, so the next click fails the same way.
Suggested fix
Route these through the existing None-returning accessor tool.Ifc.get_entity_by_id in a small helper that, on a dead id, reports the error and rebuilds the list with the disable_editing_representation_items / enable_editing_representation_items pair that these operators already use as "reload items ui". The panel then heals itself: the user gets a message instead of a traceback, a list matching the loaded IFC, and the click works on the retry.
That is a lazy fix at the point of use. The underlying condition - per-object representation-item editing state surviving an IFC load - is still there, and the fuller cure would be to reset is_editing/items on every object when a project loads. Happy to open a PR for the guards if that direction is agreeable.
Related
Instance #304 not found #6942 - same class of bug (stale Blender-side IFC id after saving .blend + .ifc together), but in tool.Geometry.get_active_representation reading the mesh props rather than the items list. Closed as stale in Sept 2025 without a fix; would still crash after the guards above.
os: Windows 10 (10.0.19045)
blender_version: 5.2
python_version: 3.13
bonsai: local build off v0.8.0; the affected code is identical on v0.9.0 @ e18d927b40
Bug Description
The Representation Items panel stores its item list in the .blend, but never checks that the ids are still valid against the loaded IFC. After a .blend/.ifc round trip (open the .blend, which reloads the .ifc next to it) the list can be replayed against a different state of the file, and the first button that touches an item raises:
Opening the same .ifc directly (no .blend) does not produce the error - the list is then rebuilt from the file that was just loaded, so every id resolves.
Cause
BIMObjectGeometryProperties.itemsis aCollectionPropertyon the object (bim/module/geometry/prop.py), sois_editingand everyitems[].ifc_definition_idare written into the .blend.EnableEditingRepresentationItemsis the only thing that rebuilds them. Nothing invalidates that list when the IFC is (re)loaded, so a list captured in one session can outlive the instances it points at, and the operators then callby_id()on a dead id with no guard.Affected call sites
All on
v0.9.0(checked at e18d927),src/bonsai/bonsai/bim/module/geometry/operator.py:RemoveRepresentationItemSelectRepresentationItemEnableEditingRepresentationItemStyle(the traceback above)EditRepresentationItemStyleEditRepresentationItemShapeAspectRemoveRepresentationItemFromShapeAspectEditRepresentationItemLayerUnassignRepresentationItemLayerUnassignRepresentationItemStylealready resolves throughtool.Ifc.get_entity_by_idand reports instead of raising, but it leaves the stale list in place, so the next click fails the same way.Suggested fix
Route these through the existing None-returning accessor
tool.Ifc.get_entity_by_idin a small helper that, on a dead id, reports the error and rebuilds the list with thedisable_editing_representation_items/enable_editing_representation_itemspair that these operators already use as "reload items ui". The panel then heals itself: the user gets a message instead of a traceback, a list matching the loaded IFC, and the click works on the retry.That is a lazy fix at the point of use. The underlying condition - per-object representation-item editing state surviving an IFC load - is still there, and the fuller cure would be to reset
is_editing/itemson every object when a project loads. Happy to open a PR for the guards if that direction is agreeable.Related
tool.Geometry.get_active_representationreading the mesh props rather than the items list. Closed as stale in Sept 2025 without a fix; would still crash after the guards above.active_item_indexwith the viewport but does not validate the ids, so it inherits the same crash.Environment