From ec38fe2edcb3f2f6070e5c2c7bbc7b152b1867cd Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Fri, 14 Jan 2022 13:15:47 +1100 Subject: [PATCH] Fix #1931. Fix bug where duplicated type products should not share material associations. --- .../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 ddbeb8fb20..deb2cb0295 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/root/copy_class.py +++ b/src/ifcopenshell-python/ifcopenshell/api/root/copy_class.py @@ -39,6 +39,10 @@ class Usecase: inverse = ifcopenshell.util.element.copy(self.file, inverse) inverse.RelatingMaterial = ifcopenshell.util.element.copy(self.file, inverse.RelatingMaterial) inverse.RelatedObjects = [to_element] + elif inverse.is_a("IfcRelAssociatesMaterial") and from_element.is_a("IfcTypeProduct"): + 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 ce7e873020..517821f73f 100644 --- a/src/ifcopenshell-python/test/api/root/test_copy_class.py +++ b/src/ifcopenshell-python/test/api/root/test_copy_class.py @@ -117,6 +117,14 @@ class TestCopyClass(test.bootstrap.IFC4): assert new.HasAssociations[0].RelatingMaterial != element.HasAssociations[0].RelatingMaterial assert new.HasAssociations[0].RelatingMaterial.is_a("IfcMaterialLayerSetUsage") + def test_copying_material_sets_for_type_elements_only(self): + element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType") + material = self.file.createIfcMaterialLayerSet() + 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("IfcMaterialLayerSet") + def test_copying_a_type_and_purging_type_relationships(self): type = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType") element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")