mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-23 21:58:46 +00:00
New feature to copy elements to multiple spatial containers
This commit is contained in:
@@ -719,6 +719,8 @@ class IfcImporter:
|
|||||||
|
|
||||||
def create_empty_products(self):
|
def create_empty_products(self):
|
||||||
for element in self.file.by_type("IfcProduct"):
|
for element in self.file.by_type("IfcProduct"):
|
||||||
|
if element.GlobalId in self.added_data:
|
||||||
|
continue
|
||||||
if not element.Representation:
|
if not element.Representation:
|
||||||
self.create_product(element)
|
self.create_product(element)
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ classes = (
|
|||||||
operator.EnableEditingContainer,
|
operator.EnableEditingContainer,
|
||||||
operator.DisableEditingContainer,
|
operator.DisableEditingContainer,
|
||||||
operator.ChangeSpatialLevel,
|
operator.ChangeSpatialLevel,
|
||||||
|
operator.CopyToContainer,
|
||||||
prop.SpatialElement,
|
prop.SpatialElement,
|
||||||
prop.BIMSpatialProperties,
|
prop.BIMSpatialProperties,
|
||||||
prop.BIMObjectSpatialProperties,
|
prop.BIMObjectSpatialProperties,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import bpy
|
import bpy
|
||||||
import ifcopenshell.api
|
import ifcopenshell.api
|
||||||
|
import ifcopenshell.util.element
|
||||||
from blenderbim.bim.ifc import IfcStore
|
from blenderbim.bim.ifc import IfcStore
|
||||||
from ifcopenshell.api.spatial.data import Data
|
from ifcopenshell.api.spatial.data import Data
|
||||||
from blenderbim.bim.module.spatial.prop import getSpatialContainers
|
from blenderbim.bim.module.spatial.prop import getSpatialContainers
|
||||||
@@ -123,3 +124,34 @@ class RemoveContainer(bpy.types.Operator):
|
|||||||
parent.children.unlink(child)
|
parent.children.unlink(child)
|
||||||
except:
|
except:
|
||||||
pass
|
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"}
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ class SpatialElement(PropertyGroup):
|
|||||||
long_name: StringProperty(name="Long Name")
|
long_name: StringProperty(name="Long Name")
|
||||||
has_decomposition: BoolProperty(name="Has Decomposition")
|
has_decomposition: BoolProperty(name="Has Decomposition")
|
||||||
ifc_definition_id: IntProperty(name="IFC Definition ID")
|
ifc_definition_id: IntProperty(name="IFC Definition ID")
|
||||||
|
is_selected: BoolProperty(name="Is Selected")
|
||||||
|
|
||||||
|
|
||||||
class BIMSpatialProperties(PropertyGroup):
|
class BIMSpatialProperties(PropertyGroup):
|
||||||
|
|||||||
@@ -40,7 +40,8 @@ class BIM_PT_spatial(Panel):
|
|||||||
op = row.operator("bim.change_spatial_level", text="", icon="FRAME_PREV")
|
op = row.operator("bim.change_spatial_level", text="", icon="FRAME_PREV")
|
||||||
op.parent_id = sprops.active_decomposes_parent_id
|
op.parent_id = sprops.active_decomposes_parent_id
|
||||||
row.operator("bim.assign_container", icon="CHECKMARK")
|
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(
|
self.layout.template_list(
|
||||||
"BIM_UL_spatial_elements", "", sprops, "spatial_elements", sprops, "active_spatial_element_index"
|
"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
|
op.parent_id = item.ifc_definition_id
|
||||||
layout.label(text=item.name)
|
layout.label(text=item.name)
|
||||||
layout.label(text=item.long_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,
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user