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.
This commit is contained in:
Petru Conduraru
2026-07-16 15:12:36 +03:00
parent 00e67d7c68
commit 69479155fd
+2 -1
View File
@@ -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)