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",