material.remove_material and copy_material to handle ifc2x3 props

This commit is contained in:
Andrej730
2024-05-13 15:46:15 +05:00
parent 2f554db54b
commit 1d046eaadf
2 changed files with 23 additions and 5 deletions
@@ -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"]
@@ -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"):