diff --git a/src/bonsai/bonsai/tool/drawing.py b/src/bonsai/bonsai/tool/drawing.py index 90f0805975..aefd3d2c9c 100644 --- a/src/bonsai/bonsai/tool/drawing.py +++ b/src/bonsai/bonsai/tool/drawing.py @@ -493,8 +493,11 @@ class Drawing(bonsai.core.tool.Drawing): @classmethod def ensure_unique_identification(cls, identification: str) -> str: - attr = "DocumentId" if tool.Ifc.get_schema() == "IFC2X3" else "Identification" - ids = [getattr(d, attr) for d in tool.Ifc.get().by_type("IfcDocumentInformation") if d.Scope == "SHEET"] + ids = [ + cls.get_sheet_identification(d) + for d in tool.Ifc.get().by_type("IfcDocumentInformation") + if d.Scope == "SHEET" + ] while identification in ids: identification += "-X" return identification @@ -985,6 +988,12 @@ class Drawing(bonsai.core.tool.Drawing): else: new.identification = schedule.Identification + @classmethod + def get_sheet_identification(cls, sheet: ifcopenshell.entity_instance) -> str: + """Schema agnostic method to get IfcDocumentInformation.Identification.""" + attr = "DocumentId" if sheet.file.schema == "IFC2X3" else "Identification" + return getattr(sheet, attr) + @classmethod def import_sheets(cls) -> None: props = cls.get_document_props() @@ -994,7 +1003,7 @@ class Drawing(bonsai.core.tool.Drawing): cls.sheet_selected_states.update({s.ifc_definition_id: s.is_selected for s in props.sheets if s.is_sheet}) props.sheets.clear() sheets = [d for d in tool.Ifc.get().by_type("IfcDocumentInformation") if d.Scope == "SHEET"] - for sheet in sorted(sheets, key=lambda s: getattr(s, "Identification", getattr(s, "DocumentId", None))): + for sheet in sorted(sheets, key=lambda s: cls.get_sheet_identification(s)): new = props.sheets.add() new.ifc_definition_id = sheet.id() if tool.Ifc.get_schema() == "IFC2X3": diff --git a/src/bonsai/bonsai/tool/web.py b/src/bonsai/bonsai/tool/web.py index ec9437d4eb..c89ca76eae 100644 --- a/src/bonsai/bonsai/tool/web.py +++ b/src/bonsai/bonsai/tool/web.py @@ -741,7 +741,7 @@ class Web(bonsai.core.tool.Web): ifc_file_dir = os.path.dirname(props.ifc_file) sheets = [d for d in tool.Ifc.get().by_type("IfcDocumentInformation") if d.Scope == "SHEET"] - for sheet in sorted(sheets, key=lambda s: getattr(s, "Identification", getattr(s, "DocumentId", None))): + for sheet in sorted(sheets, key=lambda s: tool.Drawing.get_sheet_identification(s)): for reference in tool.Drawing.get_document_references(sheet): reference_description = tool.Drawing.get_reference_description(reference) if reference_description != "SHEET":