mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-20 15:08:51 +00:00
New utility functions for copying and deep copying IFC elements
This commit is contained in:
@@ -1,3 +1,6 @@
|
|||||||
|
import ifcopenshell
|
||||||
|
|
||||||
|
|
||||||
def get_psets(element):
|
def get_psets(element):
|
||||||
psets = {}
|
psets = {}
|
||||||
try:
|
try:
|
||||||
@@ -134,6 +137,29 @@ def remove_deep(ifc_file, element):
|
|||||||
ifc_file.unbatch()
|
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):
|
def get_representation(element, context, subcontext=None, target_view=None):
|
||||||
if element.is_a("IfcProduct") and element.Representation:
|
if element.is_a("IfcProduct") and element.Representation:
|
||||||
for r in element.Representation.Representations:
|
for r in element.Representation.Representations:
|
||||||
|
|||||||
Reference in New Issue
Block a user