From 0ee084b5d999b06d0ea80cda5b220bf8d300fd32 Mon Sep 17 00:00:00 2001 From: Ryan Schultz Date: Mon, 1 Dec 2025 17:34:37 -0600 Subject: [PATCH] Support IfcAnnotation to IfcAnnotation assignment in AssignSelectedObjectAsProduct --- .../bonsai/bim/module/drawing/operator.py | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/drawing/operator.py b/src/bonsai/bonsai/bim/module/drawing/operator.py index d4b24a5ae7..db46b08e60 100644 --- a/src/bonsai/bonsai/bim/module/drawing/operator.py +++ b/src/bonsai/bonsai/bim/module/drawing/operator.py @@ -3275,15 +3275,31 @@ class AssignSelectedObjectAsProduct(bpy.types.Operator): element1 = tool.Ifc.get_entity(obj1) element2 = tool.Ifc.get_entity(obj2) assert element1 and element2 - if element1.is_a("IfcAnnotation"): + + # Check if at least one object is an IfcAnnotation + is_annotation1 = element1.is_a("IfcAnnotation") + is_annotation2 = element2.is_a("IfcAnnotation") + + if not (is_annotation1 or is_annotation2): + self.report({"ERROR"}, "At least one of the selected objects must be IfcAnnotation.") + return {"CANCELLED"} + + # If both are annotations, use the currently active object as relating product + if is_annotation1 and is_annotation2: + active_obj = context.active_object + if active_obj == obj1: + other_selected_object = obj1 + bpy.context.view_layer.objects.active = obj2 + else: + other_selected_object = obj2 + bpy.context.view_layer.objects.active = obj1 + # If only one is an annotation, make it the active object + elif is_annotation1: other_selected_object = obj2 bpy.context.view_layer.objects.active = obj1 - elif element2.is_a("IfcAnnotation"): + else: other_selected_object = obj1 bpy.context.view_layer.objects.active = obj2 - else: - self.report({"ERROR"}, "One of the selected objects must be IfcAnnotation.") - return {"CANCELLED"} assert (active_obj := context.active_object) props = tool.Drawing.get_object_assigned_product_props(active_obj)