Skip to content

Commit

Permalink
Fix support for document references in IFC2X3
Browse files Browse the repository at this point in the history
  • Loading branch information
Moult committed Oct 19, 2022
1 parent 7f278fb commit 16b05d9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
21 changes: 14 additions & 7 deletions src/blenderbim/blenderbim/bim/module/document/data.py
Expand Up @@ -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):
Expand Down
Expand Up @@ -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"])
15 changes: 15 additions & 0 deletions src/ifcopenshell-python/test/api/document/test_add_reference_.py
Expand Up @@ -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

0 comments on commit 16b05d9

Please sign in to comment.