From 7c38705958fc5fa82c93b3d8bda833ef1ae48a3a Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Tue, 13 May 2025 13:09:32 +1000 Subject: [PATCH] Accommodate invalid missing mapped representations and items coming from Tekla (2023) --- src/bonsai/bonsai/bim/import_ifc.py | 2 +- .../ifcopenshell/util/representation.py | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/bonsai/bonsai/bim/import_ifc.py b/src/bonsai/bonsai/bim/import_ifc.py index f0e76f6aaa..02f066d3ee 100644 --- a/src/bonsai/bonsai/bim/import_ifc.py +++ b/src/bonsai/bonsai/bim/import_ifc.py @@ -428,7 +428,7 @@ class IfcImporter: rep = representation while True: - if len(rep.Items) == 1 and rep.Items[0].is_a("IfcMappedItem"): + if rep.Items and len(rep.Items) == 1 and rep.Items[0].is_a("IfcMappedItem"): rep_matrix = ifcopenshell.util.placement.get_mappeditem_transformation(rep.Items[0]) if not np.allclose(rep_matrix, np.eye(4)): matrix = rep_matrix @ matrix diff --git a/src/ifcopenshell-python/ifcopenshell/util/representation.py b/src/ifcopenshell-python/ifcopenshell/util/representation.py index 94ec3f8579..53bf307c17 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/representation.py +++ b/src/ifcopenshell-python/ifcopenshell/util/representation.py @@ -294,8 +294,12 @@ def resolve_representation(representation: ifcopenshell.entity_instance) -> ifco :param representation: IfcRepresentation :return: Representation resolved from mappings """ - if len(representation.Items) == 1 and representation.Items[0].is_a("IfcMappedItem"): - return resolve_representation(representation.Items[0].MappingSource.MappedRepresentation) + if ( + len(representation.Items or []) == 1 + and representation.Items[0].is_a("IfcMappedItem") + and (mapped_rep := representation.Items[0].MappingSource.MappedRepresentation) + ): + return resolve_representation(mapped_rep) return representation