From bdcebd0f985585a732808e4b5e4ce02b8e9d3822 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Fri, 27 Jun 2025 14:28:37 +0500 Subject: [PATCH] document.add_information - error handling in case project is not found --- .../ifcopenshell/api/document/add_information.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/api/document/add_information.py b/src/ifcopenshell-python/ifcopenshell/api/document/add_information.py index 2370e222d4..f05cc5d646 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/document/add_information.py +++ b/src/ifcopenshell-python/ifcopenshell/api/document/add_information.py @@ -59,8 +59,10 @@ def add_information( """ id_attribute = "DocumentId" if file.schema == "IFC2X3" else "Identification" information = file.create_entity("IfcDocumentInformation", **{id_attribute: "X", "Name": "Unnamed"}) - if not parent and file.by_type("IfcProject"): - parent = file.by_type("IfcProject")[0] + + if not parent and not (parent := next(iter(file.by_type("IfcProject")), None)): + raise Exception("IfcProject is not found.") + if parent.is_a("IfcProject") or parent.is_a("IfcContext"): file.create_entity( "IfcRelAssociatesDocument",