From 11d57874cfbad1d3d7cb178c5b08f04baa5762d5 Mon Sep 17 00:00:00 2001 From: Petru Conduraru Date: Sun, 12 Jul 2026 09:02:20 +0300 Subject: [PATCH] Bonsai: guard MEP Add Bend against parallel segments (#6393) Adding a bend between two parallel (or collinear) MEP segments crashed with `TypeError: 'NoneType' object is not subscriptable` in MEPAddBend._execute. tool.Cad.intersect_edges returns None when the two segment axes have no unique intersection (parallel/collinear/zero-length), and the code immediately subscripted the result with [0]. The auto-dispatch "Add Fitting" path already guards is_parallel before calling, but the direct bim.mep_add_bend operator (the "Add Bend" button and the edit-preview flow) did not. Capture the intersect_edges result and, when it is None, report a user-facing error ("The two segments are parallel, so a bend cannot be computed") and return CANCELLED instead of subscripting None. Verified live in headless Blender: two parallel duct segments reproduced the exact TypeError before the fix and now cancel with the clear message; a perpendicular pair still creates the bend (IfcDuctFitting + Bend type), so no regression. Generated with the assistance of an AI coding tool. Co-Authored-By: Claude Opus 4.8 --- src/bonsai/bonsai/bim/module/model/mep.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/model/mep.py b/src/bonsai/bonsai/bim/module/model/mep.py index 2a906d4ec4..a5c277209e 100644 --- a/src/bonsai/bonsai/bim/module/model/mep.py +++ b/src/bonsai/bonsai/bim/module/model/mep.py @@ -1260,10 +1260,21 @@ class MEPAddBend(bpy.types.Operator, tool.Ifc.Operator): } get_z_basis = lambda o: tool.Cad.get_basis_vector(o, 2) - segments_intersection_ws = tool.Cad.intersect_edges( + segments_intersection = tool.Cad.intersect_edges( (start_object.location, start_object.location + get_z_basis(start_object)), (end_object.location, end_object.location + get_z_basis(end_object)), - )[0] + ) + # intersect_edges returns None when the two segment axes are parallel or + # collinear (no unique intersection). Report a clean error instead of + # crashing with "'NoneType' object is not subscriptable". + if segments_intersection is None: + self.report( + {"ERROR"}, + "The two segments are parallel, so a bend cannot be computed. " + "Select two non-parallel segments.", + ) + return {"CANCELLED"} + segments_intersection_ws = segments_intersection[0] start_point, first_segment_start = tool.Cad.closest_and_furthest_vectors( segments_intersection_ws, (start_segment_data["start_point"], start_segment_data["end_point"])