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.
This commit is contained in:
Ryan Schultz
2025-11-08 12:46:33 -06:00
parent 83e0fa1287
commit 5a511eecc1
+14 -3
View File
@@ -60,10 +60,21 @@ def edit_assigned_product(
) -> None: ) -> None:
element = ifc.get_entity(obj) element = ifc.get_entity(obj)
assert element assert element
existing_product = drawing.get_assigned_product(element)
if existing_product != product: # Get ALL existing products, not just one
if existing_product: 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) ifc.run("drawing.unassign_product", relating_product=existing_product, related_object=element)
# Assign to the new product
if product: if product:
ifc.run("drawing.assign_product", relating_product=product, related_object=element) ifc.run("drawing.assign_product", relating_product=product, related_object=element)