diff --git a/src/bonsai/bonsai/bim/module/brick/data.py b/src/bonsai/bonsai/bim/module/brick/data.py index e414723594..593ba929ae 100644 --- a/src/bonsai/bonsai/bim/module/brick/data.py +++ b/src/bonsai/bonsai/bim/module/brick/data.py @@ -156,16 +156,13 @@ class BrickschemaReferencesData: for rel in getattr(tool.Ifc.get_entity(bpy.context.active_object), "HasAssociations", []): if rel.is_a("IfcRelAssociatesLibrary"): reference = rel.RelatingLibrary - if tool.Ifc.get_schema() == "IFC2X3" and "#" not in reference.ItemReference: - continue - if tool.Ifc.get_schema() != "IFC2X3" and "#" not in reference.Identification: + identification = tool.Document.get_external_reference_id(reference) + if not identification or "#" not in identification: continue results.append( { "id": reference.id(), - "identification": ( - reference.ItemReference if tool.Ifc.get_schema() == "IFC2X3" else reference.Identification - ), + "identification": identification, "name": reference.Name or "Unnamed", } ) diff --git a/src/bonsai/bonsai/bim/module/document/data.py b/src/bonsai/bonsai/bim/module/document/data.py index f194e2f4e0..9ee22b1f09 100644 --- a/src/bonsai/bonsai/bim/module/document/data.py +++ b/src/bonsai/bonsai/bim/module/document/data.py @@ -127,36 +127,25 @@ class ObjectDocumentData: identification = None if is_information: - if tool.Ifc.get_schema() == "IFC2X3": - identification = relating_document.DocumentId - else: - identification = relating_document.Identification + identification = tool.Document.get_document_information_id(relating_document) location = getattr(relating_document, "Location", None) description = getattr(relating_document, "Description", "No description") else: description = relating_document.Description - if tool.Ifc.get_schema() == "IFC2X3": - reference_to_document = relating_document.ReferenceToDocument - if not name and reference_to_document: - name = reference_to_document[0].Name + referenced_document = tool.Document.get_reference_document(relating_document) - identification = relating_document.ItemReference - if not identification and reference_to_document: - identification = reference_to_document[0].DocumentId - location = relating_document.Location - else: - referenced_document = relating_document.ReferencedDocument - if not name and referenced_document: - name = referenced_document.Name + if not name and referenced_document: + name = referenced_document.Name - identification = relating_document.Identification - if not identification and referenced_document: - identification = referenced_document.Identification + identification = tool.Document.get_external_reference_id(relating_document) + if not identification and referenced_document: + identification = tool.Document.get_document_information_id(referenced_document) - location = relating_document.Location - if location is None and referenced_document: - location = referenced_document.Location + location = relating_document.Location + # IFC2X3 IfcDocumentInformation has no Location to fall back to. + if location is None and referenced_document and tool.Ifc.get_schema() != "IFC2X3": + location = referenced_document.Location location = cls.convert_to_file_uri(location) if location else None diff --git a/src/bonsai/bonsai/bim/module/drawing/operator.py b/src/bonsai/bonsai/bim/module/drawing/operator.py index 6846b1b91c..b1c4c69c3b 100644 --- a/src/bonsai/bonsai/bim/module/drawing/operator.py +++ b/src/bonsai/bonsai/bim/module/drawing/operator.py @@ -3586,7 +3586,7 @@ class EditSheet(bpy.types.Operator, tool.Ifc.Operator): if sheet.is_a("IfcDocumentInformation"): self.document_type = "SHEET" self.name = sheet.Name - self.identification = sheet.DocumentId if tool.Ifc.get_schema() == "IFC2X3" else sheet.Identification + self.identification = tool.Document.get_document_information_id(sheet) elif sheet.is_a("IfcDocumentReference") and tool.Drawing.get_reference_description(sheet) == "TITLEBLOCK": self.document_type = "TITLEBLOCK" else: diff --git a/src/bonsai/bonsai/bim/module/drawing/svgwriter.py b/src/bonsai/bonsai/bim/module/drawing/svgwriter.py index 9b2910b9a0..8093a5e72a 100644 --- a/src/bonsai/bonsai/bim/module/drawing/svgwriter.py +++ b/src/bonsai/bonsai/bim/module/drawing/svgwriter.py @@ -903,12 +903,8 @@ class SvgWriter: continue sheet = tool.Drawing.get_reference_document(sheet_reference) if sheet: - if tool.Ifc.get_schema() == "IFC2X3": - reference_id = sheet_reference.ItemReference or "-" - sheet_id = sheet.DocumentId or "-" - else: - reference_id = sheet_reference.Identification or "-" - sheet_id = sheet.Identification or "-" + reference_id = tool.Document.get_external_reference_id(sheet_reference) or "-" + sheet_id = tool.Document.get_document_information_id(sheet) or "-" return (reference_id, sheet_id) break return ("-", "-") diff --git a/src/bonsai/bonsai/bim/module/library/data.py b/src/bonsai/bonsai/bim/module/library/data.py index 0d26369035..8465a583c6 100644 --- a/src/bonsai/bonsai/bim/module/library/data.py +++ b/src/bonsai/bonsai/bim/module/library/data.py @@ -103,9 +103,7 @@ class LibraryReferencesData: results.append( { "id": library.id(), - "identification": ( - library.ItemReference if tool.Ifc.get_schema() == "IFC2X3" else library.Identification - ), + "identification": tool.Document.get_external_reference_id(library), "name": library.Name or "Unnamed", } ) diff --git a/src/bonsai/bonsai/tool/brick.py b/src/bonsai/bonsai/tool/brick.py index 7ef2c30444..31a607f7f1 100644 --- a/src/bonsai/bonsai/tool/brick.py +++ b/src/bonsai/bonsai/tool/brick.py @@ -192,10 +192,9 @@ class Brick(bonsai.core.tool.Brick): def get_brick(cls, element: ifcopenshell.entity_instance) -> Union[str, None]: for rel in element.HasAssociations: if rel.is_a("IfcRelAssociatesLibrary"): - if tool.Ifc.get_schema() == "IFC2X3" and "#" in rel.RelatingLibrary.ItemReference: - return rel.RelatingLibrary.ItemReference - if tool.Ifc.get_schema() != "IFC2X3" and "#" in rel.RelatingLibrary.Identification: - return rel.RelatingLibrary.Identification + identification = tool.Document.get_external_reference_id(rel.RelatingLibrary) + if identification and "#" in identification: + return identification @classmethod def get_brick_class(cls, element: ifcopenshell.entity_instance) -> Union[str, None]: diff --git a/src/bonsai/bonsai/tool/document.py b/src/bonsai/bonsai/tool/document.py index 910ca92cf4..3ecce68fc2 100644 --- a/src/bonsai/bonsai/tool/document.py +++ b/src/bonsai/bonsai/tool/document.py @@ -261,7 +261,8 @@ class Document(bonsai.core.tool.Document): def get_reference_document(cls, reference: ifcopenshell.entity_instance) -> ifcopenshell.entity_instance | None: # TODO: migrate to util.document and replace all instances if reference.file.schema == "IFC2X3": - return (reference.ReferenceToDocument or (None))[0] + reference_to_document = reference.ReferenceToDocument + return reference_to_document[0] if reference_to_document else None return reference.ReferencedDocument @classmethod diff --git a/src/bonsai/bonsai/tool/drawing.py b/src/bonsai/bonsai/tool/drawing.py index b6d68dbc6a..7493b02d33 100644 --- a/src/bonsai/bonsai/tool/drawing.py +++ b/src/bonsai/bonsai/tool/drawing.py @@ -1167,10 +1167,7 @@ class Drawing(bonsai.core.tool.Drawing): new = documents_collection.add() new.ifc_definition_id = schedule.id() new.name = schedule.Name or "Unnamed" - if tool.Ifc.get_schema() == "IFC2X3": - new.identification = schedule.DocumentId - else: - new.identification = schedule.Identification + new.identification = tool.Document.get_document_information_id(schedule) or "" @classmethod def get_sheet_identification(cls, sheet: ifcopenshell.entity_instance) -> str: @@ -1211,10 +1208,7 @@ class Drawing(bonsai.core.tool.Drawing): new.ifc_definition_id = reference.id() new.is_sheet = False - if tool.Ifc.get_schema() == "IFC2X3": - new.identification = reference.ItemReference or "" - else: - new.identification = reference.Identification or "" + new.identification = tool.Document.get_external_reference_id(reference) or "" new.name = os.path.basename(reference.Location) new.reference_type = reference_description @@ -2450,9 +2444,8 @@ class Drawing(bonsai.core.tool.Drawing): def get_reference_document( cls, reference: ifcopenshell.entity_instance ) -> Union[ifcopenshell.entity_instance, None]: - if tool.Ifc.get_schema() == "IFC2X3": - return reference.ReferenceToDocument[0] - return reference.ReferencedDocument + # TODO: migrate to document.get_reference_document. + return tool.Document.get_reference_document(reference) @classmethod def select_assigned_product(cls, context: bpy.types.Context) -> None: