From 6bde619fe66c60a5b5e3cfed4526b36bc7796335 Mon Sep 17 00:00:00 2001 From: Gorgious56 Date: Fri, 22 May 2026 13:32:08 +0200 Subject: [PATCH] Migrate MEPConnectElements args from object names to IFC GUIDs MEPConnectElements took obj1_name/obj2_name (Blender object names), which break when objects are renamed or replicated by array duplication. Switch to obj1_guid/obj2_guid resolved via ifc_file.by_guid, with by_guid RuntimeError surfaced as an operator error rather than a stack trace. DrawPolylineProfile (the sole in-tree caller) updates to pass GlobalIds. Generated with the assistance of an AI coding tool. --- src/bonsai/bonsai/bim/module/model/profile.py | 3 ++- .../bonsai/bim/module/system/operator.py | 20 ++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/model/profile.py b/src/bonsai/bonsai/bim/module/model/profile.py index e5c0991e8e..d6fcb4c6fd 100644 --- a/src/bonsai/bonsai/bim/module/model/profile.py +++ b/src/bonsai/bonsai/bim/module/model/profile.py @@ -1157,7 +1157,8 @@ class DrawPolylineProfile(bpy.types.Operator, PolylineOperator, tool.Ifc.Operato DumbProfileJoiner().join_V(profile2["obj"], profile1["obj"]) if connect_IfcFlowSegments: bpy.ops.bim.mep_connect_elements( - obj1_name=profile1["obj"].name, obj2_name=profile2["obj"].name + obj1_guid=tool.Ifc.get_entity(profile1["obj"]).GlobalId, + obj2_guid=tool.Ifc.get_entity(profile2["obj"]).GlobalId, ) def modal(self, context, event): diff --git a/src/bonsai/bonsai/bim/module/system/operator.py b/src/bonsai/bonsai/bim/module/system/operator.py index 5fe47564c0..8ff18f4704 100644 --- a/src/bonsai/bonsai/bim/module/system/operator.py +++ b/src/bonsai/bonsai/bim/module/system/operator.py @@ -317,13 +317,23 @@ class MEPConnectElements(bpy.types.Operator, tool.Ifc.Operator): bl_label = "Connect MEP Elements" bl_description = "Connects two selected elements by their closest located ports and adjusts them" bl_options = {"REGISTER", "UNDO"} - obj1_name: bpy.props.StringProperty(name="Object 1") - obj2_name: bpy.props.StringProperty(name="Object 2") + obj1_guid: bpy.props.StringProperty(name="Object 1 GlobalId") + obj2_guid: bpy.props.StringProperty(name="Object 2 GlobalId") def _execute(self, context): - if self.obj1_name and self.obj2_name: - obj1 = bpy.data.objects.get(self.obj1_name) - obj2 = bpy.data.objects.get(self.obj2_name) + if self.obj1_guid and self.obj2_guid: + ifc_file = tool.Ifc.get() + try: + el1_lookup = ifc_file.by_guid(self.obj1_guid) + el2_lookup = ifc_file.by_guid(self.obj2_guid) + except RuntimeError: + self.report({"ERROR"}, "Could not resolve MEP elements from supplied GlobalIds.") + return {"CANCELLED"} + obj1 = tool.Ifc.get_object(el1_lookup) + obj2 = tool.Ifc.get_object(el2_lookup) + if not obj1 or not obj2: + self.report({"ERROR"}, "Supplied MEP elements have no Blender object bound.") + return {"CANCELLED"} else: if not context.selected_objects or len(context.selected_objects) != 2: self.report({"ERROR"}, "Need to select 2 objects.")