mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 17:31:45 +00:00
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:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user