You can now duplicate existing types in the type manager

This commit is contained in:
Dion Moult
2022-10-11 17:51:01 +11:00
parent 4279576d3c
commit c5c9a192b0
3 changed files with 24 additions and 0 deletions
@@ -99,6 +99,8 @@ class LaunchTypeManager(bpy.types.Operator):
op.ifc_class = relating_type["ifc_class"]
op.relating_type_id = relating_type["id"]
op = row.operator("bim.duplicate_type", icon="COPYDOWN", text="")
op.element = relating_type["id"]
op = row.operator("bim.remove_type", icon="X", text="")
op.element = relating_type["id"]
@@ -22,6 +22,7 @@ from . import ui, prop, operator
classes = (
operator.AssignType,
operator.DisableEditingType,
operator.DuplicateType,
operator.EnableEditingType,
operator.RemoveType,
operator.SelectSimilarType,
@@ -23,6 +23,7 @@ import ifcopenshell.api
import blenderbim.tool as tool
import blenderbim.core.geometry
import blenderbim.core.type as core
import blenderbim.core.root
from blenderbim.bim.ifc import IfcStore
from ifcopenshell.api.type.data import Data
from ifcopenshell.api.geometry.data import Data as GeometryData
@@ -182,3 +183,23 @@ class RemoveType(bpy.types.Operator, tool.Ifc.Operator):
tool.Ifc.unlink(obj=obj)
bpy.data.objects.remove(obj)
return {"FINISHED"}
class DuplicateType(bpy.types.Operator, tool.Ifc.Operator):
bl_idname = "bim.duplicate_type"
bl_label = "Duplicate Type"
bl_options = {"REGISTER"}
element: bpy.props.IntProperty()
def _execute(self, context):
element = tool.Ifc.get().by_id(self.element)
obj = tool.Ifc.get_object(element)
if not obj:
return {"FINISHED"}
new_obj = obj.copy()
if obj.data:
new_obj.data = obj.data.copy()
new = blenderbim.core.root.copy_class(tool.Ifc, tool.Collector, tool.Geometry, tool.Root, obj=new_obj)
new.Name += " Copy"
bpy.ops.bim.load_type_thumbnails(ifc_class=new.is_a())
return {"FINISHED"}