From bb1ec569bc163753969234f0577d8dc97e2737bf Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Tue, 21 Jan 2025 17:08:42 +0500 Subject: [PATCH] Option to name existing used unnamed profiles Example - https://imgur.com/a/IhMbs6K --- .../bonsai/bim/module/geometry/__init__.py | 1 + .../bonsai/bim/module/geometry/operator.py | 35 +++++++++++++++++++ .../bonsai/bim/module/model/workspace.py | 5 ++- 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/bonsai/bonsai/bim/module/geometry/__init__.py b/src/bonsai/bonsai/bim/module/geometry/__init__.py index bfc1fc6444..83b5134b37 100644 --- a/src/bonsai/bonsai/bim/module/geometry/__init__.py +++ b/src/bonsai/bonsai/bim/module/geometry/__init__.py @@ -42,6 +42,7 @@ classes = ( operator.FlipObject, operator.GetRepresentationIfcParameters, operator.ImportRepresentationItems, + operator.NameProfile, operator.OverrideDelete, operator.OverrideDuplicateMove, operator.OverrideDuplicateMoveLinked, diff --git a/src/bonsai/bonsai/bim/module/geometry/operator.py b/src/bonsai/bonsai/bim/module/geometry/operator.py index b2b79e6670..b6e309586d 100644 --- a/src/bonsai/bonsai/bim/module/geometry/operator.py +++ b/src/bonsai/bonsai/bim/module/geometry/operator.py @@ -2775,6 +2775,41 @@ class UpdateItemAttributes(bpy.types.Operator, tool.Ifc.Operator): tool.Root.reload_item_decorator() +class NameProfile(bpy.types.Operator, tool.Ifc.Operator): + bl_idname = "bim.name_profile" + bl_label = "Name Profile" + bl_description = "Add name to existing unnamed profile" + bl_options = {"REGISTER", "UNDO", "INTERNAL"} + + extrusion_item_obj: bpy.props.StringProperty(name="Extrusion Item Object Name") + profile_name: bpy.props.StringProperty( + name="Profile Name", + options={"SKIP_SAVE"}, + ) + + def invoke(self, context, event): + return context.window_manager.invoke_props_dialog(self) + + def draw(self, context): + layout = self.layout + layout.prop(self, "profile_name") + + def _execute(self, context): + if not self.profile_name: + self.report({"INFO"}, "Profile name is not provided") + return {"CANCELLED"} + + ifc_file = tool.Ifc.get() + extrusion_item_obj = bpy.data.objects[self.extrusion_item_obj] + mesh_props = extrusion_item_obj.data.BIMMeshProperties + extrusion = ifc_file.by_id(mesh_props.ifc_definition_id) + assert extrusion.is_a("IfcSweptAreaSolid") + profile = extrusion.SweptArea + profile.ProfileName = self.profile_name + bonsai.bim.handler.refresh_ui_data() # Ensure enum is up to date. + mesh_props.item_profile = str(profile.id()) + + class AddMeshlikeItem(bpy.types.Operator, tool.Ifc.Operator): bl_idname = "bim.add_meshlike_item" bl_label = "Add Meshlike Item" diff --git a/src/bonsai/bonsai/bim/module/model/workspace.py b/src/bonsai/bonsai/bim/module/model/workspace.py index 0c00f0331b..38521a4808 100644 --- a/src/bonsai/bonsai/bim/module/model/workspace.py +++ b/src/bonsai/bonsai/bim/module/model/workspace.py @@ -285,8 +285,11 @@ class EditItemUI: mesh_props = obj.data.BIMMeshProperties if cls.get_item_object_class(obj) == "IfcExtrudedAreaSolid": - row = cls.layout.row() + row = cls.layout.row(align=True) row.prop(mesh_props, "item_profile") + if mesh_props.item_profile == "-": + op = row.operator("bim.name_profile", text="", icon="TAG") + op.extrusion_item_obj = obj.name for item_attribute in obj.data.BIMMeshProperties.item_attributes: row = cls.layout.row()