From a33a1700dce3946b57a3f85cde70bb15601ec17a Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Wed, 14 Feb 2024 14:15:02 +0500 Subject: [PATCH] Fix bug in ExtractElements recipe adding a lot unrelated products if you'd add a type product and it had material that were used in bunch of ther products example - https://community.osarch.org/discussion/1965/error-extracting-ifcslab-or-ifccolumn --- .../ifcopenshell/api/project/append_asset.py | 2 ++ .../test/api/project/test_append_asset.py | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/ifcopenshell-python/ifcopenshell/api/project/append_asset.py b/src/ifcopenshell-python/ifcopenshell/api/project/append_asset.py index aeb880550b..ae74cd3340 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/project/append_asset.py +++ b/src/ifcopenshell-python/ifcopenshell/api/project/append_asset.py @@ -261,6 +261,8 @@ class Usecase: return True elif self.target_class == "IfcProduct" and element.is_a("IfcTypeProduct"): return True + elif self.target_class == "IfcTypeProduct" and element.is_a("IfcProduct"): + return True return False def reuse_existing_contexts(self): diff --git a/src/ifcopenshell-python/test/api/project/test_append_asset.py b/src/ifcopenshell-python/test/api/project/test_append_asset.py index 290ed90399..b813c93eac 100644 --- a/src/ifcopenshell-python/test/api/project/test_append_asset.py +++ b/src/ifcopenshell-python/test/api/project/test_append_asset.py @@ -62,6 +62,25 @@ class TestAppendAsset(test.bootstrap.IFC4): ifcopenshell.api.run("project.append_asset", self.file, library=library, element=element) assert self.file.by_type("IfcWallType")[0].HasAssociations[0].RelatingMaterial.Name == "Material" + def test_append_a_type_product_where_its_inverse_material_relationship_refers_to_products_not_in_scope(self): + library = ifcopenshell.api.run("project.create_file") + element = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWall") + element_type = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWallType") + element_type2 = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWallType") + ifcopenshell.api.run("type.assign_type", library, related_object=element, relating_type=element_type) + material = ifcopenshell.api.run("material.add_material", library, name="Material") + ifcopenshell.api.run("material.assign_material", library, product=element, material=material) + ifcopenshell.api.run("material.assign_material", library, product=element_type, material=material) + ifcopenshell.api.run("material.assign_material", library, product=element_type2, material=material) + + # appending another type not connected to IfcWall directly + ifcopenshell.api.run("project.append_asset", self.file, library=library, element=element_type2) + assert set(self.file.by_type("IfcWall")) == set() + + # appending type of IfcWall + ifcopenshell.api.run("project.append_asset", self.file, library=library, element=element_type2) + assert set(self.file.by_type("IfcWall")) == set() + def test_append_two_type_products_sharing_the_same_material_with_properties(self): library = ifcopenshell.api.run("project.create_file") element1 = ifcopenshell.api.run("root.create_entity", library, ifc_class="IfcWallType")