From a5b8728aec725588a1b715612d5e7af12981ad98 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Fri, 22 Oct 2021 12:09:57 +1100 Subject: [PATCH] Fix bug where copying elements didn't ensure that material usages were unique --- .../ifcopenshell/api/root/copy_class.py | 4 ++++ src/ifcopenshell-python/test/api/root/test_copy_class.py | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/src/ifcopenshell-python/ifcopenshell/api/root/copy_class.py b/src/ifcopenshell-python/ifcopenshell/api/root/copy_class.py index fdbba11544..89d54511de 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/root/copy_class.py +++ b/src/ifcopenshell-python/ifcopenshell/api/root/copy_class.py @@ -33,6 +33,10 @@ class Usecase: continue elif inverse.is_a("IfcRelFillsElement"): continue + elif inverse.is_a("IfcRelAssociatesMaterial") and "Usage" in inverse.RelatingMaterial.is_a(): + inverse = ifcopenshell.util.element.copy(self.file, inverse) + inverse.RelatingMaterial = ifcopenshell.util.element.copy(self.file, inverse.RelatingMaterial) + inverse.RelatedObjects = [to_element] else: for i, value in enumerate(inverse): if value == from_element: diff --git a/src/ifcopenshell-python/test/api/root/test_copy_class.py b/src/ifcopenshell-python/test/api/root/test_copy_class.py index e96be46a5a..a20306befd 100644 --- a/src/ifcopenshell-python/test/api/root/test_copy_class.py +++ b/src/ifcopenshell-python/test/api/root/test_copy_class.py @@ -108,3 +108,11 @@ class TestCopyClass(test.bootstrap.IFC4): ifcopenshell.api.run("void.add_filling", self.file, opening=opening, element=door) new = ifcopenshell.api.run("root.copy_class", self.file, product=door) assert not new.FillsVoids + + def test_copying_material_set_usages(self): + element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall") + material = self.file.createIfcMaterialLayerSetUsage() + self.file.createIfcRelAssociatesMaterial(RelatedObjects=[element], RelatingMaterial=material) + new = ifcopenshell.api.run("root.copy_class", self.file, product=element) + assert new.HasAssociations[0].RelatingMaterial != element.HasAssociations[0].RelatingMaterial + assert new.HasAssociations[0].RelatingMaterial.is_a("IfcMaterialLayerSetUsage")