From 16b05d9981d490823d2fe4acbd80e1ba674b7606 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Wed, 19 Oct 2022 20:15:51 +1100 Subject: [PATCH] Fix support for document references in IFC2X3 --- .../blenderbim/bim/module/document/data.py | 21 ++++++++++++------- .../api/document/add_reference.py | 7 ++++++- .../test/api/document/test_add_reference_.py | 15 +++++++++++++ 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/document/data.py b/src/blenderbim/blenderbim/bim/module/document/data.py index 3b056bec32b..b273f83a346 100644 --- a/src/blenderbim/blenderbim/bim/module/document/data.py +++ b/src/blenderbim/blenderbim/bim/module/document/data.py @@ -84,21 +84,28 @@ def documents(cls): continue name = rel.RelatingDocument.Name - if not name and rel.RelatingDocument.ReferencedDocument: - name = rel.RelatingDocument.ReferencedDocument.Name if tool.Ifc.get_schema() == "IFC2X3": + if not name and rel.RelatingDocument.ReferenceToDocument: + name = rel.RelatingDocument.ReferenceToDocument[0].Name + identification = rel.RelatingDocument.ItemReference - if not identification and rel.RelatingDocument.ReferencedDocument: - identification = rel.RelatingDocument.ReferencedDocument.DocumentId + if not identification and rel.RelatingDocument.ReferenceToDocument: + identification = rel.RelatingDocument.ReferenceToDocument[0].DocumentId + + location = rel.RelatingDocument.Location else: + if not name and rel.RelatingDocument.ReferencedDocument: + name = rel.RelatingDocument.ReferencedDocument.Name + identification = rel.RelatingDocument.Identification if not identification and rel.RelatingDocument.ReferencedDocument: identification = rel.RelatingDocument.ReferencedDocument.Identification - location = rel.RelatingDocument.Location - if location is None and rel.RelatingDocument.ReferencedDocument: - location = rel.RelatingDocument.ReferencedDocument.Location + location = rel.RelatingDocument.Location + if location is None and rel.RelatingDocument.ReferencedDocument: + location = rel.RelatingDocument.ReferencedDocument.Location + if location: if not "://" in location: if not os.path.isabs(location): diff --git a/src/ifcopenshell-python/ifcopenshell/api/document/add_reference.py b/src/ifcopenshell-python/ifcopenshell/api/document/add_reference.py index 90505d9886a..cd476227bfd 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/document/add_reference.py +++ b/src/ifcopenshell-python/ifcopenshell/api/document/add_reference.py @@ -26,5 +26,10 @@ def __init__(self, file, **settings): def execute(self): if self.file.schema == "IFC2X3": - return self.file.create_entity("IfcDocumentReference") + reference = self.file.create_entity("IfcDocumentReference") + if self.settings["information"]: + references = list(self.settings["information"].DocumentReferences or []) + references.append(reference) + self.settings["information"].DocumentReferences = references + return reference return self.file.create_entity("IfcDocumentReference", ReferencedDocument=self.settings["information"]) diff --git a/src/ifcopenshell-python/test/api/document/test_add_reference_.py b/src/ifcopenshell-python/test/api/document/test_add_reference_.py index 584bbf44a6f..deb379cdaa8 100644 --- a/src/ifcopenshell-python/test/api/document/test_add_reference_.py +++ b/src/ifcopenshell-python/test/api/document/test_add_reference_.py @@ -33,3 +33,18 @@ def test_adding_a_reference_to_an_information(self): assert element.is_a("IfcDocumentReference") assert len(self.file.by_type("IfcDocumentReference")) == 1 assert element.ReferencedDocument == information + + +class TestAddReferenceIFC2X3(test.bootstrap.IFC2X3): + def test_adding_a_reference(self): + element = ifcopenshell.api.run("document.add_reference", self.file, information=None) + assert element.is_a("IfcDocumentReference") + assert len(self.file.by_type("IfcDocumentReference")) == 1 + + def test_adding_a_reference_to_an_information(self): + self.file.createIfcProject() + information = ifcopenshell.api.run("document.add_information", self.file, parent=None) + element = ifcopenshell.api.run("document.add_reference", self.file, information=information) + assert element.is_a("IfcDocumentReference") + assert len(self.file.by_type("IfcDocumentReference")) == 1 + assert element.ReferenceToDocument[0] == information