From 397f13e71cafafa76f1b4e845c0034091367c5b9 Mon Sep 17 00:00:00 2001 From: Ryan Schultz Date: Sat, 18 Jul 2026 15:26:42 -0500 Subject: [PATCH] Bonsai: add Delete Type button to Type Attributes panel Adds a trash button in BIM_PT_type_attributes that deletes the relating type via bim.remove_type. SHIFT+Click also deletes every occurrence of the type in the project, behind a confirmation dialog showing the count. Co-Authored-By: Claude Opus 4.8 --- src/bonsai/bonsai/bim/module/type/operator.py | 33 +++++++++++++++++-- src/bonsai/bonsai/bim/module/type/ui.py | 4 ++- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/type/operator.py b/src/bonsai/bonsai/bim/module/type/operator.py index 7b306b1b31..bcaf8a98c7 100644 --- a/src/bonsai/bonsai/bim/module/type/operator.py +++ b/src/bonsai/bonsai/bim/module/type/operator.py @@ -305,14 +305,43 @@ class SelectTypeObjects(bpy.types.Operator): class RemoveType(bpy.types.Operator, tool.Ifc.Operator): bl_idname = "bim.remove_type" - bl_label = "Remove Type" + bl_label = "Delete Type" + bl_description = ( + "Delete this type. Its occurrences are kept but become untyped.\n\n" + "SHIFT+Click to also delete every occurrence of this type in the project" + ) bl_options = {"REGISTER", "UNDO"} element: bpy.props.IntProperty() + also_delete_instances: bpy.props.BoolProperty(default=False, options={"SKIP_SAVE"}) + + if TYPE_CHECKING: + element: int + also_delete_instances: bool + + def invoke(self, context, event): + self.also_delete_instances = event.shift + if self.also_delete_instances: + element = tool.Ifc.get().by_id(self.element) + count = len(ifcopenshell.util.element.get_types(element)) + return context.window_manager.invoke_confirm( + self, + event, + title="Delete Type and Occurrences", + message=f"This will delete the type and all {count} of its occurrences.", + confirm_text="Delete", + ) + return self.execute(context) def _execute(self, context): element = tool.Ifc.get().by_id(self.element) + if self.also_delete_instances: + for occurrence in ifcopenshell.util.element.get_types(element): + occurrence_obj = tool.Ifc.get_object(occurrence) + if occurrence_obj: + tool.Geometry.delete_ifc_object(occurrence_obj) obj = tool.Ifc.get_object(element) - tool.Geometry.delete_ifc_object(obj) + if obj: + tool.Geometry.delete_ifc_object(obj) class RenameType(bpy.types.Operator, tool.Ifc.Operator): diff --git a/src/bonsai/bonsai/bim/module/type/ui.py b/src/bonsai/bonsai/bim/module/type/ui.py index 1848858953..3c8d875a4c 100644 --- a/src/bonsai/bonsai/bim/module/type/ui.py +++ b/src/bonsai/bonsai/bim/module/type/ui.py @@ -144,8 +144,10 @@ class BIM_PT_type_attributes(Panel): bonsai.bim.helper.draw_attributes(props.type_attributes, layout) else: - row = layout.row() + row = layout.row(align=True) row.operator("bim.enable_editing_type_attributes", icon="GREASEPENCIL", text="Edit") + op = row.operator("bim.remove_type", icon="TRASH", text="") + op.element = TypeData.data["relating_type"]["id"] for attribute in TypeData.data["relating_type_attributes"]: row = layout.row(align=True)