From b8a9674483bcfa96455c9590fcb938081b07a239 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Tue, 23 Apr 2024 16:39:46 +0500 Subject: [PATCH] bim.duplicate_profile simple operator for profile duplication example - https://imgur.com/a/dsP78iV --- .../blenderbim/bim/module/profile/__init__.py | 1 + .../blenderbim/bim/module/profile/operator.py | 21 +++++++++++++++++++ .../blenderbim/bim/module/profile/ui.py | 1 + src/blenderbim/blenderbim/tool/profile.py | 5 +++++ 4 files changed, 28 insertions(+) diff --git a/src/blenderbim/blenderbim/bim/module/profile/__init__.py b/src/blenderbim/blenderbim/bim/module/profile/__init__.py index 69a153e315..89e20c8af7 100644 --- a/src/blenderbim/blenderbim/bim/module/profile/__init__.py +++ b/src/blenderbim/blenderbim/bim/module/profile/__init__.py @@ -21,6 +21,7 @@ from . import ui, prop, operator, data classes = ( operator.AddProfileDef, + operator.DuplicateProfileDef, operator.DisableEditingArbitraryProfile, operator.DisableEditingProfile, operator.DisableProfileEditingUI, diff --git a/src/blenderbim/blenderbim/bim/module/profile/operator.py b/src/blenderbim/blenderbim/bim/module/profile/operator.py index 188cceaf26..6886d6e77c 100644 --- a/src/blenderbim/blenderbim/bim/module/profile/operator.py +++ b/src/blenderbim/blenderbim/bim/module/profile/operator.py @@ -132,6 +132,27 @@ class AddProfileDef(bpy.types.Operator, tool.Ifc.Operator): bpy.ops.bim.load_profiles() +class DuplicateProfileDef(bpy.types.Operator, tool.Ifc.Operator): + bl_idname = "bim.duplicate_profile_def" + bl_label = "Duplicate Profile" + bl_options = {"REGISTER", "UNDO"} + + @classmethod + def poll(cls, context): + props = context.scene.BIMProfileProperties + if len(props.profiles) > props.active_profile_index: + return True + cls.poll_message_set("No profile selected to duplicate.") + return False + + def _execute(self, context): + props = context.scene.BIMProfileProperties + ifc_file = tool.Ifc.get() + profile = ifc_file.by_id(props.profiles[props.active_profile_index].ifc_definition_id) + tool.Profile.duplicate_profile(profile) + bpy.ops.bim.load_profiles() + + class EnableEditingArbitraryProfile(bpy.types.Operator, tool.Ifc.Operator): bl_idname = "bim.enable_editing_arbitrary_profile" bl_label = "Enable Editing Arbitrary Profile" diff --git a/src/blenderbim/blenderbim/bim/module/profile/ui.py b/src/blenderbim/blenderbim/bim/module/profile/ui.py index 85e407b2e3..f1bce17c83 100644 --- a/src/blenderbim/blenderbim/bim/module/profile/ui.py +++ b/src/blenderbim/blenderbim/bim/module/profile/ui.py @@ -70,6 +70,7 @@ class BIM_PT_profiles(Panel): row = self.layout.row(align=True) row.prop(self.props, "profile_classes", text="") row.operator("bim.add_profile_def", text="", icon="ADD") + row.operator("bim.duplicate_profile_def", icon="DUPLICATE", text="") self.layout.template_list( "BIM_UL_profiles", diff --git a/src/blenderbim/blenderbim/tool/profile.py b/src/blenderbim/blenderbim/tool/profile.py index 92086a91ca..fdce5011e9 100644 --- a/src/blenderbim/blenderbim/tool/profile.py +++ b/src/blenderbim/blenderbim/tool/profile.py @@ -17,6 +17,7 @@ # along with BlenderBIM Add-on. If not, see . import ifcopenshell +import ifcopenshell.util.element import ifcopenshell.util.unit import ifcopenshell.util.placement import ifcopenshell.util.representation @@ -75,3 +76,7 @@ class Profile(blenderbim.core.tool.Profile): @classmethod def get_model_profiles(cls): return tool.Ifc.get().by_type("IfcProfileDef") + + @classmethod + def duplicate_profile(cls, profile: ifcopenshell.entity_instance) -> ifcopenshell.entity_instance: + return ifcopenshell.util.element.copy_deep(tool.Ifc.get(), profile)