mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-11 02:02:22 +00:00
Auto create relevant context when attempting to add an annotation to make it friendlier for new users.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user