From 1d046eaadf24480c9cd02172b0640931ab979ef2 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Mon, 13 May 2024 15:46:15 +0500 Subject: [PATCH] material.remove_material and copy_material to handle ifc2x3 props --- .../api/material/copy_material.py | 20 +++++++++++++++---- .../api/material/remove_material.py | 8 +++++++- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/api/material/copy_material.py b/src/ifcopenshell-python/ifcopenshell/api/material/copy_material.py index c862e9cb4b..45886e7121 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/material/copy_material.py +++ b/src/ifcopenshell-python/ifcopenshell/api/material/copy_material.py @@ -48,11 +48,23 @@ def copy_material(file, material=None) -> None: if inverse.is_a("IfcMaterialProperties"): # Properties must not be shared between objects for convenience of authoring inverse = ifcopenshell.util.element.copy(file, inverse) - properties = [] - for pset in inverse.Properties: - properties.append(ifcopenshell.util.element.copy_deep(file, pset)) - inverse.Properties = properties inverse.Material = new + + props_attribute = "Properties" + if file.schema == "IFC2X3": + if not inverse.is_a("IfcExtendedMaterialProperties"): + continue + props_attribute = "ExtendedProperties" + + props = getattr(inverse, props_attribute) + if not props: + continue + + copied_props = [] + for pset in props: + copied_props.append(ifcopenshell.util.element.copy_deep(file, pset)) + setattr(inverse, props_attribute, copied_props) + elif inverse.is_a("IfcMaterialDefinitionRepresentation"): inverse = ifcopenshell.util.element.copy_deep( file, inverse, exclude=["IfcRepresentationContext", "IfcMaterial"] diff --git a/src/ifcopenshell-python/ifcopenshell/api/material/remove_material.py b/src/ifcopenshell-python/ifcopenshell/api/material/remove_material.py index a59fee6caf..1b0924f717 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/material/remove_material.py +++ b/src/ifcopenshell-python/ifcopenshell/api/material/remove_material.py @@ -62,7 +62,13 @@ def remove_material(file, material=None) -> None: if history: ifcopenshell.util.element.remove_deep2(file, history) elif inverse.is_a("IfcMaterialProperties"): - for prop in inverse.Properties or []: + if file.schema != "IFC2X3": + props = inverse.Properties + else: + # only IfcExtendedMaterialProperties have properties in IFC2X3 + props = getattr(inverse, "ExtendedProperties", None) + props = props or [] + for prop in props: file.remove(prop) file.remove(inverse) elif inverse.is_a("IfcMaterialDefinitionRepresentation"):