mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-05 23:41:44 +00:00
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 <noreply@anthropic.com>
(cherry picked from commit 397f13e71c)
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user