From 4a8b863b9657f248d51b12b7bd7599dc8ae72f9f Mon Sep 17 00:00:00 2001 From: Petru Conduraru Date: Tue, 30 Jun 2026 08:00:07 +0300 Subject: [PATCH] test(ifcpatch): ExtractElements regression test for georeferencing loss (#8199) Co-Authored-By: Claude Sonnet 4.6 --- src/ifcpatch/test/test_ExtractElements.py | 27 +++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/ifcpatch/test/test_ExtractElements.py b/src/ifcpatch/test/test_ExtractElements.py index 8d7d4021c6..24b717328c 100644 --- a/src/ifcpatch/test/test_ExtractElements.py +++ b/src/ifcpatch/test/test_ExtractElements.py @@ -20,6 +20,8 @@ import os import ifcopenshell import ifcopenshell.api.aggregate +import ifcopenshell.api.context +import ifcopenshell.api.georeference import ifcopenshell.api.root import ifcopenshell.api.spatial import ifcopenshell.util.element @@ -79,6 +81,31 @@ class TestExtractElements(test.bootstrap.IFC4): assert output.by_type("IfcWall") assert not output.by_type("IfcSlab") + def test_preserving_georeferencing(self): + # Regression test for #8199: ExtractElements must carry IfcMapConversion + # and IfcProjectedCRS into the output. Without the fix these entities are + # silently dropped because they reference the IfcGeometricRepresentationContext + # via an inverse attribute and are therefore not reachable through the + # IfcProject forward-attribute walk used by self.new.add(). + if self.file.schema == "IFC2X3": + pytest.skip("IfcMapConversion does not exist in IFC2X3") + ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProject") + ifcopenshell.api.context.add_context(self.file, context_type="Model") + ifcopenshell.api.georeference.add_georeferencing(self.file) + ifcopenshell.api.georeference.edit_georeferencing( + self.file, + coordinate_operation={"Eastings": 100000.0, "Northings": 200000.0}, + ) + ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall") + + output = ifcpatch.execute({"file": self.file, "recipe": "ExtractElements", "arguments": ["IfcWall"]}) + + assert len(output.by_type("IfcMapConversion")) == 1 + assert len(output.by_type("IfcProjectedCRS")) == 1 + conversion = output.by_type("IfcMapConversion")[0] + assert conversion.Eastings == 100000.0 + assert conversion.Northings == 200000.0 + @pytest.mark.skipif( "IFC4X3" not in ifcopenshell.ifcopenshell_wrapper.schema_names(), reason=(