New utility functions for copying and deep copying IFC elements

This commit is contained in:
Dion Moult
2021-05-13 15:11:18 +10:00
parent 3b33977acc
commit 4e014d1a10
@@ -1,3 +1,6 @@
import ifcopenshell
def get_psets(element):
psets = {}
try:
@@ -134,6 +137,29 @@ def remove_deep(ifc_file, element):
ifc_file.unbatch()
def copy(ifc_file, element):
new = ifc_file.create_entity(element.is_a())
for i, attribute in enumerate(element):
if attribute is None:
continue
new[i] = attribute
return new
def copy_deep(ifc_file, element):
new = ifc_file.create_entity(element.is_a())
for i, attribute in enumerate(element):
if attribute is None:
continue
if isinstance(attribute, ifcopenshell.entity_instance):
attribute = copy_deep(ifc_file, attribute)
elif isinstance(attribute, tuple) and attribute and isinstance(attribute[0], ifcopenshell.entity_instance):
for j, item in enumerate(attribute):
attribute[j] = copy_deep(ifc_file, item)
new[i] = attribute
return new
def get_representation(element, context, subcontext=None, target_view=None):
if element.is_a("IfcProduct") and element.Representation:
for r in element.Representation.Representations: