From fed98451d47957f930106d39c778b7da922b3e38 Mon Sep 17 00:00:00 2001 From: falken10vdl Date: Tue, 27 Jan 2026 01:32:06 +0100 Subject: [PATCH] connect the ports when creating several conected IfcFlowSegment with polyline --- src/bonsai/bonsai/bim/module/model/profile.py | 6 ++++++ .../bonsai/bim/module/system/operator.py | 20 ++++++++++--------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/model/profile.py b/src/bonsai/bonsai/bim/module/model/profile.py index 9271f2acc1..0a11fa191b 100644 --- a/src/bonsai/bonsai/bim/module/model/profile.py +++ b/src/bonsai/bonsai/bim/module/model/profile.py @@ -1131,8 +1131,14 @@ class DrawPolylineProfile(bpy.types.Operator, PolylineOperator, tool.Ifc.Operato MEPGenerator().setup_ports(profile1["obj"]) else: + connect_IfcFlowSegments = tool.Ifc.get_entity(profiles[0]["obj"]).is_a("IfcFlowSegment") for profile1, profile2 in zip(profiles[:-1], profiles[1:]): 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 + ) def modal(self, context, event): return IfcStore.execute_ifc_operator(self, context, event, method="MODAL") diff --git a/src/bonsai/bonsai/bim/module/system/operator.py b/src/bonsai/bonsai/bim/module/system/operator.py index 8dd6724de3..5fecd05ffb 100644 --- a/src/bonsai/bonsai/bim/module/system/operator.py +++ b/src/bonsai/bonsai/bim/module/system/operator.py @@ -317,17 +317,19 @@ 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"} - - @classmethod - def poll(cls, context): - if not len(context.selected_objects) == 2: - cls.poll_message_set("Need to select 2 objects.") - return False - return True + obj1_name: bpy.props.StringProperty(name="Object 1") + obj2_name: bpy.props.StringProperty(name="Object 2") def _execute(self, context): - obj1 = context.active_object - obj2 = next(o for o in context.selected_objects if o != obj1) + if self.obj1_name and self.obj2_name: + obj1 = bpy.data.objects.get(self.obj1_name) + obj2 = bpy.data.objects.get(self.obj2_name) + else: + if not context.selected_objects or len(context.selected_objects) != 2: + self.report({"ERROR"}, "Need to select 2 objects.") + return {"CANCELLED"} + obj1 = context.active_object + obj2 = next(o for o in context.selected_objects if o != obj1) tool.Model.sync_object_ifc_position(obj1) tool.Model.sync_object_ifc_position(obj2)