From 2739df865656010cda2bf08a64554a57d4542f11 Mon Sep 17 00:00:00 2001 From: Ryan Schultz Date: Thu, 20 Aug 2026 11:58:52 -0500 Subject: [PATCH] Bonsai: keep shared annotations when removing a drawing remove_drawing deleted every element in the drawing's group, so an annotation shared with other drawings was destroyed along with the drawing it was removed from. It now excludes annotations that are still assigned to more than one drawing from deletion; group.remove_group drops only this drawing's membership rel, so the shared annotation stays on its other drawings. The drawing camera and annotations unique to this drawing are still deleted. Co-Authored-By: Claude Opus 4.8 --- src/bonsai/bonsai/core/drawing.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/bonsai/bonsai/core/drawing.py b/src/bonsai/bonsai/core/drawing.py index 5591f57f35..663e852d20 100644 --- a/src/bonsai/bonsai/core/drawing.py +++ b/src/bonsai/bonsai/core/drawing.py @@ -438,7 +438,19 @@ def remove_drawing( group = drawing_tool.get_drawing_group(drawing) if group: - drawing_tool.delete_drawing_elements(drawing_tool.get_group_elements(group)) + # Annotations shared with other drawings must survive this removal - only + # detach them from this drawing. group.remove_group drops this group's + # membership rel, so a shared annotation stays on its other drawings. + to_delete = [ + e + for e in drawing_tool.get_group_elements(group) + if not ( + e.is_a("IfcAnnotation") + and e.ObjectType != "DRAWING" + and len(drawing_tool.get_annotation_drawings(e)) > 1 + ) + ] + drawing_tool.delete_drawing_elements(to_delete) ifc.run("group.remove_group", group=group) drawing_tool.import_drawings()