document.add_information - error handling in case project is not found

This commit is contained in:
Andrej730
2025-06-27 14:28:37 +05:00
parent 9278974d98
commit bdcebd0f98
@@ -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",