From 69479155fd68ff2be3cdf8ed453afdfd2a1df585 Mon Sep 17 00:00:00 2001 From: Petru Conduraru Date: Thu, 16 Jul 2026 15:12:36 +0300 Subject: [PATCH] Bonsai: fix UnboundLocalError when a None-geometry item is a SweptAreaSolid The previous commit guarded import_item against tool.Loader.create_generic_shape returning None, but only assigned cartesian_point_offset inside the walrus operator of the non-None branch. When geometry is None and the item is also an IfcSweptAreaSolid, the code after the if/else unconditionally reads cartesian_point_offset to adjust item_matrix, raising an UnboundLocalError instead of the intended graceful error log. Move the cartesian_point_offset lookup out of the walrus operator so it is always computed, matching its use later in the function regardless of which branch ran. Verified live in headless Blender: reproduced both the original AttributeError ('NoneType' has no attribute 'verts_buffer', matching the issue's traceback) and this UnboundLocalError with a synthetic IfcExtrudedAreaSolid item whose create_generic_shape was made to return None (the reporter's real .ifc file was shared privately with maintainers and was not available to us); confirmed the fixed code path completes without crashing and logs the error instead. Fixes #6693. Generated with the assistance of an AI coding tool. --- src/bonsai/bonsai/tool/geometry.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/bonsai/bonsai/tool/geometry.py b/src/bonsai/bonsai/tool/geometry.py index cae18e2139..bb9a16cb91 100644 --- a/src/bonsai/bonsai/tool/geometry.py +++ b/src/bonsai/bonsai/tool/geometry.py @@ -2229,6 +2229,7 @@ class Geometry(bonsai.core.tool.Geometry): co = np.array(item.VertexGeometry.Coordinates) * ifcopenshell.util.unit.calculate_unit_scale(tool.Ifc.get()) obj.data.from_pydata([co], [], []) else: + cartesian_point_offset = cls.get_cartesian_point_offset(rep_obj) geometry = tool.Loader.create_generic_shape(item) if geometry is None: # The geometry kernel can legitimately fail to produce a shape for an @@ -2248,7 +2249,7 @@ class Geometry(bonsai.core.tool.Geometry): obj.matrix_world = rep_obj.matrix_world.copy() else: verts = ifcopenshell.util.shape.get_vertices(geometry) - if (cartesian_point_offset := cls.get_cartesian_point_offset(rep_obj)) is not None: + if cartesian_point_offset is not None: verts = verts - cartesian_point_offset tool.Loader.convert_geometry_to_mesh(geometry, obj.data, verts=verts)