From 595a3b3f87a050a0b4288d11f55204e5f424dcb3 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Tue, 14 Jan 2025 14:22:15 +1100 Subject: [PATCH] Preselect IFC class when adding elements for convenience. --- src/bonsai/bonsai/bim/module/model/ui.py | 4 +++- src/bonsai/bonsai/bim/module/root/operator.py | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/model/ui.py b/src/bonsai/bonsai/bim/module/model/ui.py index f4dd8e2989..384534975d 100644 --- a/src/bonsai/bonsai/bim/module/model/ui.py +++ b/src/bonsai/bonsai/bim/module/model/ui.py @@ -112,7 +112,9 @@ class LaunchTypeManager(bpy.types.Operator): row.menu("BIM_MT_type_manager_menu", text="", icon="PREFERENCES") row = self.layout.row(align=True) - row.operator("bim.launch_add_element", text=f"Create New {AuthoringData.data['ifc_element_type'] or 'Type'}", icon="ADD") + row.operator( + "bim.add_element", text=f"Create New {AuthoringData.data['ifc_element_type'] or 'Type'}", icon="ADD" + ).ifc_class = (AuthoringData.data["ifc_element_type"] or "") if AuthoringData.data["total_types"]: row = self.layout.row(align=True) diff --git a/src/bonsai/bonsai/bim/module/root/operator.py b/src/bonsai/bonsai/bim/module/root/operator.py index 36b2f21e09..b8f9f745f8 100644 --- a/src/bonsai/bonsai/bim/module/root/operator.py +++ b/src/bonsai/bonsai/bim/module/root/operator.py @@ -341,16 +341,20 @@ class AddElement(bpy.types.Operator, tool.Ifc.Operator): bl_label = "Add Element" bl_options = {"REGISTER", "UNDO"} bl_description = "Add an IFC physical product, construction type, and more" + ifc_class: bpy.props.StringProperty(options={"SKIP_SAVE"}) def invoke(self, context, event): return IfcStore.execute_ifc_operator(self, context, is_invoke=True) def _invoke(self, context, event): + props = context.scene.BIMRootProperties # For convenience, preselect OBJ representation template if applicable if (obj := context.active_object) and obj.type == "MESH": - props = context.scene.BIMRootProperties props.representation_template = "OBJ" props.representation_obj = obj + # For convenience, preselect IFC class + if self.ifc_class: + props.ifc_class = self.ifc_class return context.window_manager.invoke_props_dialog(self) def _execute(self, context):