From fd62ba63a56059f5c670ff42f78b7e752f530d58 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Sat, 25 May 2024 15:14:07 +1000 Subject: [PATCH] Do not copy presentation styles when copying a material Ideally, presentation styles are reused. For example, 5 types of concrete can all use the same presentation --- .../ifcopenshell/api/material/copy_material.py | 5 ++++- .../test/api/material/test_copy_material.py | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ifcopenshell-python/ifcopenshell/api/material/copy_material.py b/src/ifcopenshell-python/ifcopenshell/api/material/copy_material.py index 535f4f5b44..2bb91a4ba7 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/material/copy_material.py +++ b/src/ifcopenshell-python/ifcopenshell/api/material/copy_material.py @@ -29,6 +29,9 @@ def copy_material(file: ifcopenshell.file, material: ifcopenshell.entity_instanc If a material set is copied, the set items are also copied. However the underlying materials (and profiles) used within the set items are reused. + If a material is associated with a presentation style, that presentation + style is reused. + :param material: The IfcMaterialDefinition to copy :type material: ifcopenshell.entity_instance :return: The new copy of the material @@ -92,7 +95,7 @@ def _copy_material_with_inverses(file, material): elif inverse.is_a("IfcMaterialDefinitionRepresentation"): inverse = ifcopenshell.util.element.copy_deep( - file, inverse, exclude=["IfcRepresentationContext", "IfcMaterial"] + file, inverse, exclude=["IfcRepresentationContext", "IfcMaterial", "IfcPresentationStyle"] ) inverse.RepresentedMaterial = new return new diff --git a/src/ifcopenshell-python/test/api/material/test_copy_material.py b/src/ifcopenshell-python/test/api/material/test_copy_material.py index e9c2d599d4..3f88d6732d 100644 --- a/src/ifcopenshell-python/test/api/material/test_copy_material.py +++ b/src/ifcopenshell-python/test/api/material/test_copy_material.py @@ -67,6 +67,7 @@ class TestCopyMaterial(test.bootstrap.IFC4): ifcopenshell.api.run("style.assign_material_style", self.file, material=material, style=style, context=context) new = ifcopenshell.api.run("material.copy_material", self.file, material=material) assert new.Name == "CON01" + assert len(self.file.by_type("IfcPresentationStyle")) == 1 assert len(self.file.by_type("IfcMaterialDefinitionRepresentation")) == 2 assert new.HasRepresentation[0] != material.HasRepresentation[0] assert new.HasRepresentation[0].Representations[0] != material.HasRepresentation[0].Representations[0]