From 0daf4c93240251a8e8827d23a1a808a686817646 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Perdig=C3=A3o?= Date: Fri, 15 Nov 2024 10:53:31 -0300 Subject: [PATCH] Remove constraints when object is unassigned from the aggregate. --- src/bonsai/bonsai/bim/module/aggregate/operator.py | 2 ++ src/bonsai/bonsai/tool/aggregate.py | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/bonsai/bonsai/bim/module/aggregate/operator.py b/src/bonsai/bonsai/bim/module/aggregate/operator.py index 4950d48a07..b827a1028f 100644 --- a/src/bonsai/bonsai/bim/module/aggregate/operator.py +++ b/src/bonsai/bonsai/bim/module/aggregate/operator.py @@ -96,6 +96,8 @@ class BIM_OT_aggregate_unassign_object(bpy.types.Operator, tool.Ifc.Operator): related_obj=tool.Ifc.get_object(element), ) + tool.Aggregate.remove_constraints(tool.Ifc.get_object(element)) + # Removes Pset related to Linked Aggregates if not element.is_a("IfcElementAssembly"): pset = ifcopenshell.util.element.get_pset(element, "BBIM_Linked_Aggregate") diff --git a/src/bonsai/bonsai/tool/aggregate.py b/src/bonsai/bonsai/tool/aggregate.py index bbe8e20277..e0423439f7 100644 --- a/src/bonsai/bonsai/tool/aggregate.py +++ b/src/bonsai/bonsai/tool/aggregate.py @@ -85,7 +85,7 @@ class Aggregate(bonsai.core.tool.Aggregate): return parts @classmethod - def constrain_parts_to_aggregate(cls, aggregate: ifcopenshell.entity_instance): + def constrain_parts_to_aggregate(cls, aggregate: bpy.types.Object): agg_element = tool.Ifc.get_entity(aggregate) parts = ifcopenshell.util.element.get_parts(agg_element) parts_objs = [tool.Ifc.get_object(p) for p in parts] @@ -95,3 +95,11 @@ class Aggregate(bonsai.core.tool.Aggregate): obj.constraints.remove(constraint) constraint = obj.constraints.new("CHILD_OF") constraint.target = aggregate + + @classmethod + def remove_constraints(cls, part: bpy.types.Object): + constraint = next((c for c in part.constraints if c.type == "CHILD_OF"), None) + if constraint: + part.constraints.remove(constraint) + +