From f31df307c60cb9365e2b9a9a9ed465e1806ff608 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Mon, 6 Oct 2025 15:46:16 +1100 Subject: [PATCH] Fix #6674. Bug where newly created annotation types didn't have the necessary metadata for item editing. --- src/bonsai/bonsai/bim/module/drawing/operator.py | 5 ++++- src/bonsai/bonsai/core/drawing.py | 3 +-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/drawing/operator.py b/src/bonsai/bonsai/bim/module/drawing/operator.py index b5b9ae7d6d..5fcaa92d4a 100644 --- a/src/bonsai/bonsai/bim/module/drawing/operator.py +++ b/src/bonsai/bonsai/bim/module/drawing/operator.py @@ -106,14 +106,17 @@ class AddAnnotationType(bpy.types.Operator, tool.Ifc.Operator): obj = bpy.data.objects.new(object_type, None) obj.name = props.type_name + ifc_context = ifcopenshell.util.representation.get_context(tool.Ifc.get(), "Model", "Annotation", "MODEL_VIEW") element = tool.Drawing.run_root_assign_class( obj=obj, ifc_class="IfcTypeProduct", predefined_type=object_type, should_add_representation=has_representation, - context=ifcopenshell.util.representation.get_context(tool.Ifc.get(), "Model", "Annotation", "MODEL_VIEW"), + context=ifc_context, ifc_representation_class=tool.Drawing.get_ifc_representation_class(object_type), ) + if representation := tool.Drawing.get_representation(element, ifc_context): + tool.Drawing.reload_representation(obj=obj, representation=representation) element.ApplicableOccurrence = f"IfcAnnotation/{object_type}" if props.create_representation_for_type and object_type == "IMAGE": diff --git a/src/bonsai/bonsai/core/drawing.py b/src/bonsai/bonsai/core/drawing.py index 2763f72ea0..cdf97a41fa 100644 --- a/src/bonsai/bonsai/core/drawing.py +++ b/src/bonsai/bonsai/core/drawing.py @@ -440,8 +440,7 @@ def add_annotation( drawing_tool.show_decorations() obj = drawing_tool.create_annotation_object(drawing, object_type) element = ifc.get_entity(obj) - # TODO: element is never None? - if not element: + if not element: # Brand new annotation relating_type_rep = drawing_tool.get_annotation_representation(relating_type) if relating_type else None element = drawing_tool.run_root_assign_class( obj=obj,