From 5a511eecc1691b80167745dce08bebb1d69eec34 Mon Sep 17 00:00:00 2001 From: Ryan Schultz Date: Sat, 8 Nov 2025 12:46:33 -0600 Subject: [PATCH] Fix #4014: Unassign annotation from all products before reassignment The edit_assigned_product() function now removes the annotation from all existing IfcRelAssignsToProduct relationships instead of just one, preventing annotations from being incorrectly assigned to multiple products simultaneously. This fixes issues where leader lines wouldn't update correctly because the annotation retained old product assignments. --- src/bonsai/bonsai/core/drawing.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/bonsai/bonsai/core/drawing.py b/src/bonsai/bonsai/core/drawing.py index d769079acc..4a378a7e73 100644 --- a/src/bonsai/bonsai/core/drawing.py +++ b/src/bonsai/bonsai/core/drawing.py @@ -60,10 +60,21 @@ def edit_assigned_product( ) -> None: element = ifc.get_entity(obj) assert element - existing_product = drawing.get_assigned_product(element) - if existing_product != product: - if existing_product: + + # Get ALL existing products, not just one + existing_products = [] + if hasattr(element, 'HasAssignments'): + for rel in element.HasAssignments: + if rel.is_a('IfcRelAssignsToProduct'): + existing_products.append(rel.RelatingProduct) + + # Only proceed if the assignment is different + if not (len(existing_products) == 1 and existing_products[0] == product): + # Unassign from ALL existing products + for existing_product in existing_products: ifc.run("drawing.unassign_product", relating_product=existing_product, related_object=element) + + # Assign to the new product if product: ifc.run("drawing.assign_product", relating_product=product, related_object=element)