Auto create relevant context when attempting to add an annotation to make it friendlier for new users.

This commit is contained in:
Dion Moult
2023-08-11 22:41:24 +10:00
parent 3345d7e088
commit 3c5ad1328f
2 changed files with 24 additions and 4 deletions
+3 -4
View File
@@ -345,11 +345,10 @@ def update_drawing_name(ifc, drawing_tool, drawing=None, name=None):
def add_annotation(ifc, collector, drawing_tool, drawing=None, object_type=None):
context = drawing_tool.get_annotation_context(
target_view := drawing_tool.get_drawing_target_view(drawing), object_type
)
target_view = drawing_tool.get_drawing_target_view(drawing)
context = drawing_tool.get_annotation_context(target_view, object_type)
if not context:
return f"No annotation context Annotation/{target_view} for drawing"
context = drawing_tool.create_annotation_context(target_view, object_type)
drawing_tool.show_decorations()
obj = drawing_tool.create_annotation_object(drawing, object_type)
+21
View File
@@ -345,6 +345,27 @@ class Drawing(blenderbim.core.tool.Drawing):
literals.append(literal_data)
return literals
@classmethod
def create_annotation_context(cls, target_view, object_type=None):
# checking PLAN target view and annotation type that doesn't require 3d
if target_view in ("PLAN_VIEW", "REFLECTED_PLAN_VIEW") and object_type not in (
"FALL",
"SECTION_LEVEL",
"PLAN_LEVEL",
):
parent = ifcopenshell.util.representation.get_context(tool.Ifc.get(), "Plan")
else:
parent = ifcopenshell.util.representation.get_context(tool.Ifc.get(), "Model")
return ifcopenshell.api.run(
"context.add_context",
tool.Ifc.get(),
context_type=parent.ContextType,
context_identifier="Annotation",
target_view=target_view,
parent=parent,
)
@classmethod
def get_annotation_context(cls, target_view, object_type=None):
# checking PLAN target view and annotation type that doesn't require 3d