mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-20 23:36:20 +00:00
document.add_information - error handling in case project is not found
This commit is contained in:
@@ -59,8 +59,10 @@ def add_information(
|
|||||||
"""
|
"""
|
||||||
id_attribute = "DocumentId" if file.schema == "IFC2X3" else "Identification"
|
id_attribute = "DocumentId" if file.schema == "IFC2X3" else "Identification"
|
||||||
information = file.create_entity("IfcDocumentInformation", **{id_attribute: "X", "Name": "Unnamed"})
|
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"):
|
if parent.is_a("IfcProject") or parent.is_a("IfcContext"):
|
||||||
file.create_entity(
|
file.create_entity(
|
||||||
"IfcRelAssociatesDocument",
|
"IfcRelAssociatesDocument",
|
||||||
|
|||||||
Reference in New Issue
Block a user