Compare commits

...

1 Commits

Author SHA1 Message Date
Ryan Schultz d71b9c9c8c Auto-create body context when adding drawing
If the Model/Body/MODEL_VIEW context does not exist in the
IFC file, get_body_context now creates it (and the Model
parent if also missing) rather than returning None and
crashing with an AssertionError.

Generated with the assistance of an AI coding tool.
2026-03-28 09:43:51 -05:00
+13 -1
View File
@@ -670,7 +670,19 @@ class Drawing(bonsai.core.tool.Drawing):
@classmethod
def get_body_context(cls) -> ifcopenshell.entity_instance:
return ifcopenshell.util.representation.get_context(tool.Ifc.get(), "Model", "Body", "MODEL_VIEW")
context = ifcopenshell.util.representation.get_context(tool.Ifc.get(), "Model", "Body", "MODEL_VIEW")
if context:
return context
parent = ifcopenshell.util.representation.get_context(tool.Ifc.get(), "Model")
if not parent:
parent = ifcopenshell.api.context.add_context(tool.Ifc.get(), context_type="Model")
return ifcopenshell.api.context.add_context(
tool.Ifc.get(),
context_type="Model",
context_identifier="Body",
target_view="MODEL_VIEW",
parent=parent,
)
@classmethod
def get_document_uri(