Skip to content
This repository was archived by the owner on Nov 24, 2024. It is now read-only.

Commit 1d046ea

Browse files
committed
material.remove_material and copy_material to handle ifc2x3 props
1 parent 2f554db commit 1d046ea

2 files changed

Lines changed: 23 additions & 5 deletions

File tree

src/ifcopenshell-python/ifcopenshell/api/material/copy_material.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,23 @@ def copy_material(file, material=None) -> None:
4848
if inverse.is_a("IfcMaterialProperties"):
4949
# Properties must not be shared between objects for convenience of authoring
5050
inverse = ifcopenshell.util.element.copy(file, inverse)
51-
properties = []
52-
for pset in inverse.Properties:
53-
properties.append(ifcopenshell.util.element.copy_deep(file, pset))
54-
inverse.Properties = properties
5551
inverse.Material = new
52+
53+
props_attribute = "Properties"
54+
if file.schema == "IFC2X3":
55+
if not inverse.is_a("IfcExtendedMaterialProperties"):
56+
continue
57+
props_attribute = "ExtendedProperties"
58+
59+
props = getattr(inverse, props_attribute)
60+
if not props:
61+
continue
62+
63+
copied_props = []
64+
for pset in props:
65+
copied_props.append(ifcopenshell.util.element.copy_deep(file, pset))
66+
setattr(inverse, props_attribute, copied_props)
67+
5668
elif inverse.is_a("IfcMaterialDefinitionRepresentation"):
5769
inverse = ifcopenshell.util.element.copy_deep(
5870
file, inverse, exclude=["IfcRepresentationContext", "IfcMaterial"]

src/ifcopenshell-python/ifcopenshell/api/material/remove_material.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,13 @@ def remove_material(file, material=None) -> None:
6262
if history:
6363
ifcopenshell.util.element.remove_deep2(file, history)
6464
elif inverse.is_a("IfcMaterialProperties"):
65-
for prop in inverse.Properties or []:
65+
if file.schema != "IFC2X3":
66+
props = inverse.Properties
67+
else:
68+
# only IfcExtendedMaterialProperties have properties in IFC2X3
69+
props = getattr(inverse, "ExtendedProperties", None)
70+
props = props or []
71+
for prop in props:
6672
file.remove(prop)
6773
file.remove(inverse)
6874
elif inverse.is_a("IfcMaterialDefinitionRepresentation"):

0 commit comments

Comments
 (0)