From c5a7a8680e7e9c206db562f14f5e3675d6677992 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Wed, 8 May 2024 15:12:45 +0500 Subject: [PATCH] fix removing references in ifc2x3 #4636 --- .../ifcopenshell/api/document/remove_reference.py | 10 +++++++--- .../test/api/document/test_remove_reference.py | 4 ++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/api/document/remove_reference.py b/src/ifcopenshell-python/ifcopenshell/api/document/remove_reference.py index 5321b480f7..42264cdec3 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/document/remove_reference.py +++ b/src/ifcopenshell-python/ifcopenshell/api/document/remove_reference.py @@ -38,11 +38,15 @@ def remove_reference(file: ifcopenshell.file, reference: ifcopenshell.entity_ins reference = ifcopenshell.api.run("document.add_reference", model, information=document) ifcopenshell.api.run("document.remove_reference", model, reference=reference) """ - settings = {"reference": reference} - for rel in settings["reference"].DocumentRefForObjects or []: + if file.schema == "IFC2X3": + rels = [r for r in file.get_inverse(reference) if r.is_a("IfcRelAssociatesDocument")] + else: + rels = reference.DocumentRefForObjects + + for rel in rels: history = rel.OwnerHistory file.remove(rel) if history: ifcopenshell.util.element.remove_deep2(file, history) - file.remove(settings["reference"]) + file.remove(reference) diff --git a/src/ifcopenshell-python/test/api/document/test_remove_reference.py b/src/ifcopenshell-python/test/api/document/test_remove_reference.py index a1b3c260e2..8fc96200ab 100644 --- a/src/ifcopenshell-python/test/api/document/test_remove_reference.py +++ b/src/ifcopenshell-python/test/api/document/test_remove_reference.py @@ -41,3 +41,7 @@ class TestRemoveReference(test.bootstrap.IFC4): assert len(self.file.by_type("IfcDocumentReference")) == 0 assert len(self.file.by_type("IfcDocumentInformation")) == 1 assert len(self.file.by_type("IfcRelAssociatesDocument")) == 1 + + +class TestRemoveReferenceIFC2X3(test.bootstrap.IFC2X3, TestRemoveReference): + pass