diff --git a/src/blenderbim/blenderbim/bim/module/style/__init__.py b/src/blenderbim/blenderbim/bim/module/style/__init__.py index 7871feabac..becd598f33 100644 --- a/src/blenderbim/blenderbim/bim/module/style/__init__.py +++ b/src/blenderbim/blenderbim/bim/module/style/__init__.py @@ -30,6 +30,7 @@ classes = ( operator.DisableAddingPresentationStyle, operator.DisableEditingStyle, operator.DisableEditingStyles, + operator.DuplicateStyle, operator.EditStyle, operator.EditSurfaceStyle, operator.EnableAddingPresentationStyle, diff --git a/src/blenderbim/blenderbim/bim/module/style/operator.py b/src/blenderbim/blenderbim/bim/module/style/operator.py index db679a6cf8..8133f16a5a 100644 --- a/src/blenderbim/blenderbim/bim/module/style/operator.py +++ b/src/blenderbim/blenderbim/bim/module/style/operator.py @@ -493,6 +493,22 @@ class EnableAddingPresentationStyle(bpy.types.Operator, tool.Ifc.Operator): props.is_adding = True +class DuplicateStyle(bpy.types.Operator, tool.Ifc.Operator): + bl_idname = "bim.duplicate_style" + bl_label = "Duplicate Style" + bl_options = {"REGISTER", "UNDO"} + + style: bpy.props.IntProperty(name="Style ID") + + def _execute(self, context): + style_type = context.scene.BIMStylesProperties.style_type + ifc_file = tool.Ifc.get() + style = ifc_file.by_id(self.style) + tool.Style.duplicate_style(style) + bpy.ops.bim.disable_editing_styles() + bpy.ops.bim.load_styles(style_type=style_type) + + class DisableAddingPresentationStyle(bpy.types.Operator, tool.Ifc.Operator): bl_idname = "bim.disable_adding_presentation_style" bl_label = "Disable Add Presentation Style" diff --git a/src/blenderbim/blenderbim/bim/module/style/ui.py b/src/blenderbim/blenderbim/bim/module/style/ui.py index 404bf3e26c..0804098577 100644 --- a/src/blenderbim/blenderbim/bim/module/style/ui.py +++ b/src/blenderbim/blenderbim/bim/module/style/ui.py @@ -85,6 +85,7 @@ class BIM_PT_styles(Panel): op = row.operator("bim.enable_editing_style", text="Edit Style", icon="GREASEPENCIL") op.style = style.ifc_definition_id + row.operator("bim.duplicate_style", text="", icon="DUPLICATE").style = style.ifc_definition_id row.operator("bim.select_by_style", text="", icon="RESTRICT_SELECT_OFF").style = style.ifc_definition_id row.operator("bim.remove_style", text="", icon="X").style = style.ifc_definition_id diff --git a/src/blenderbim/blenderbim/tool/style.py b/src/blenderbim/blenderbim/tool/style.py index 30628cb1ef..88d6c23a77 100644 --- a/src/blenderbim/blenderbim/tool/style.py +++ b/src/blenderbim/blenderbim/tool/style.py @@ -19,6 +19,7 @@ import bpy import numpy as np import ifcopenshell +import ifcopenshell.util.element import blenderbim.core.tool import blenderbim.tool as tool import blenderbim.bim.helper @@ -59,6 +60,10 @@ class Style(blenderbim.core.tool.Style): def disable_editing_styles(cls): bpy.context.scene.BIMStylesProperties.is_editing = False + @classmethod + def duplicate_style(cls, style: ifcopenshell.entity_instance) -> ifcopenshell.entity_instance: + return ifcopenshell.util.element.copy_deep(tool.Ifc.get(), style) + @classmethod def enable_editing(cls, obj): obj.BIMStyleProperties.is_editing = True