From d911f1844921e894e9eaa710be94f1c7dfa74cf0 Mon Sep 17 00:00:00 2001 From: Ryan Schultz Date: Wed, 29 Jul 2026 10:46:00 -0500 Subject: [PATCH] Bonsai: remove every selected annotation from a drawing, not just the active one RemoveAnnotationFromDrawing read context.active_object, so taking several annotations off a drawing meant selecting and clicking them one at a time, even though AddAnnotationToDrawing already works across the whole selection. It now mirrors the add operator: every selected IfcAnnotation that is actually on this drawing is removed, drawing annotations are skipped, and the outcome is reported as removed and skipped counts. The skipped count covers annotations that must stay on at least one drawing, which the old code could only report for the active object. Co-Authored-By: Claude Opus 5 --- .../bonsai/bim/module/drawing/operator.py | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/drawing/operator.py b/src/bonsai/bonsai/bim/module/drawing/operator.py index 92238f7c92..84a805222f 100644 --- a/src/bonsai/bonsai/bim/module/drawing/operator.py +++ b/src/bonsai/bonsai/bim/module/drawing/operator.py @@ -1968,7 +1968,7 @@ class AddAnnotationToDrawing(bpy.types.Operator, tool.Ifc.Operator): class RemoveAnnotationFromDrawing(bpy.types.Operator, tool.Ifc.Operator): bl_idname = "bim.remove_annotation_from_drawing" bl_label = "Remove Annotation From Drawing" - bl_description = "Remove the active annotation from this drawing (it stays on its other drawings)" + bl_description = "Remove the selected annotation(s) from this drawing (they stay on their other drawings)" bl_options = {"REGISTER", "UNDO"} drawing_id: bpy.props.IntProperty(options={"SKIP_SAVE"}) @@ -1980,13 +1980,30 @@ class RemoveAnnotationFromDrawing(bpy.types.Operator, tool.Ifc.Operator): return bool(element and element.is_a("IfcAnnotation") and element.ObjectType != "DRAWING") def _execute(self, context): - element = tool.Ifc.get_entity(context.active_object) drawing = tool.Ifc.get().by_id(self.drawing_id) - if not core.remove_annotation_from_drawing( - tool.Ifc, tool.Collector, tool.Drawing, element=element, drawing=drawing - ): - self.report({"WARNING"}, "An annotation must remain on at least one drawing.") - return + # Mirror AddAnnotationToDrawing: act on every selected annotation that is + # actually on this drawing, not just the active one. + elements = [ + element + for o in tool.Blender.get_selected_objects() + if (element := tool.Ifc.get_entity(o)) + and element.is_a("IfcAnnotation") + and element.ObjectType != "DRAWING" + and drawing in tool.Drawing.get_annotation_drawings(element) + ] + removed = 0 + skipped = 0 + for element in elements: + if core.remove_annotation_from_drawing( + tool.Ifc, tool.Collector, tool.Drawing, element=element, drawing=drawing + ): + removed += 1 + else: + skipped += 1 + msg = f"Removed {removed} annotation(s) from {drawing.Name or 'drawing'}." + if skipped: + msg += f" Skipped {skipped} (must remain on at least one drawing)." + self.report({"INFO"}, msg) for area in context.screen.areas: if area.type == "PROPERTIES": area.tag_redraw()