diff --git a/src/blenderbim/blenderbim/bim/import_ifc.py b/src/blenderbim/blenderbim/bim/import_ifc.py index da6bbb21f4..321066267c 100644 --- a/src/blenderbim/blenderbim/bim/import_ifc.py +++ b/src/blenderbim/blenderbim/bim/import_ifc.py @@ -719,6 +719,8 @@ class IfcImporter: def create_empty_products(self): for element in self.file.by_type("IfcProduct"): + if element.GlobalId in self.added_data: + continue if not element.Representation: self.create_product(element) diff --git a/src/blenderbim/blenderbim/bim/module/spatial/__init__.py b/src/blenderbim/blenderbim/bim/module/spatial/__init__.py index 7004764078..8671309965 100644 --- a/src/blenderbim/blenderbim/bim/module/spatial/__init__.py +++ b/src/blenderbim/blenderbim/bim/module/spatial/__init__.py @@ -7,6 +7,7 @@ classes = ( operator.EnableEditingContainer, operator.DisableEditingContainer, operator.ChangeSpatialLevel, + operator.CopyToContainer, prop.SpatialElement, prop.BIMSpatialProperties, prop.BIMObjectSpatialProperties, diff --git a/src/blenderbim/blenderbim/bim/module/spatial/operator.py b/src/blenderbim/blenderbim/bim/module/spatial/operator.py index ae512da728..3ce1dda70f 100644 --- a/src/blenderbim/blenderbim/bim/module/spatial/operator.py +++ b/src/blenderbim/blenderbim/bim/module/spatial/operator.py @@ -1,5 +1,6 @@ import bpy import ifcopenshell.api +import ifcopenshell.util.element from blenderbim.bim.ifc import IfcStore from ifcopenshell.api.spatial.data import Data from blenderbim.bim.module.spatial.prop import getSpatialContainers @@ -123,3 +124,34 @@ class RemoveContainer(bpy.types.Operator): parent.children.unlink(child) except: pass + + +class CopyToContainer(bpy.types.Operator): + bl_idname = "bim.copy_to_container" + bl_label = "Copy To Container" + obj: bpy.props.StringProperty() + + def execute(self, context): + self.file = IfcStore.get_file() + objects = [bpy.data.objects.get(self.obj)] if self.obj else bpy.context.selected_objects + sprops = context.scene.BIMSpatialProperties + container_ids = [c.ifc_definition_id for c in sprops.spatial_elements if c.is_selected] + for obj in objects: + container = ifcopenshell.util.element.get_container(self.file.by_id(obj.BIMObjectProperties.ifc_definition_id)) + if container: + container_obj = IfcStore.get_element(container.id()) + local_position = container_obj.matrix_world.inverted() @ obj.matrix_world + else: + local_position = obj.matrix_world + + for container_id in container_ids: + container_obj = IfcStore.get_element(container_id) + if not container_obj: + continue + new_obj = obj.copy() + new_obj.data = obj.data.copy() + new_obj.matrix_world = container_obj.matrix_world @ local_position + bpy.ops.bim.copy_class(obj=new_obj.name) + bpy.ops.bim.assign_container(relating_structure=container_id, related_element=new_obj.name) + obj.BIMObjectSpatialProperties.is_editing = False + return {"FINISHED"} diff --git a/src/blenderbim/blenderbim/bim/module/spatial/prop.py b/src/blenderbim/blenderbim/bim/module/spatial/prop.py index 4f14eacf29..dfea8823de 100644 --- a/src/blenderbim/blenderbim/bim/module/spatial/prop.py +++ b/src/blenderbim/blenderbim/bim/module/spatial/prop.py @@ -54,6 +54,7 @@ class SpatialElement(PropertyGroup): long_name: StringProperty(name="Long Name") has_decomposition: BoolProperty(name="Has Decomposition") ifc_definition_id: IntProperty(name="IFC Definition ID") + is_selected: BoolProperty(name="Is Selected") class BIMSpatialProperties(PropertyGroup): diff --git a/src/blenderbim/blenderbim/bim/module/spatial/ui.py b/src/blenderbim/blenderbim/bim/module/spatial/ui.py index a5710949f4..f5ed85f61b 100644 --- a/src/blenderbim/blenderbim/bim/module/spatial/ui.py +++ b/src/blenderbim/blenderbim/bim/module/spatial/ui.py @@ -40,7 +40,8 @@ class BIM_PT_spatial(Panel): op = row.operator("bim.change_spatial_level", text="", icon="FRAME_PREV") op.parent_id = sprops.active_decomposes_parent_id row.operator("bim.assign_container", icon="CHECKMARK") - row.operator("bim.disable_editing_container", icon="X", text="") + row.operator("bim.copy_to_container", icon="COPYDOWN", text="") + row.operator("bim.disable_editing_container", icon="CANCEL", text="") self.layout.template_list( "BIM_UL_spatial_elements", "", sprops, "spatial_elements", sprops, "active_spatial_element_index" @@ -65,3 +66,10 @@ class BIM_UL_spatial_elements(UIList): op.parent_id = item.ifc_definition_id layout.label(text=item.name) layout.label(text=item.long_name) + layout.prop( + item, + "is_selected", + icon="CHECKBOX_HLT" if item.is_selected else "CHECKBOX_DEHLT", + text="", + emboss=False, + )