Constrain part objects to aggregate object when creating aggregations.

This commit is contained in:
Bruno Perdigão
2024-11-15 08:35:30 -03:00
committed by Bruno Perdigão
parent 26ba761c68
commit cf9446c4a5
2 changed files with 14 additions and 0 deletions
@@ -66,6 +66,7 @@ class BIM_OT_aggregate_assign_object(bpy.types.Operator, tool.Ifc.Operator):
relating_obj=relating_obj,
related_obj=obj,
)
tool.Aggregate.constrain_parts_to_aggregate(relating_obj)
except core.IncompatibleAggregateError:
self.report({"ERROR"}, f"Cannot aggregate {obj.name} to {relating_obj.name}")
except core.AggregateRepresentationError:
@@ -177,6 +178,7 @@ class BIM_OT_add_aggregate(bpy.types.Operator, tool.Ifc.Operator):
element_obj=aggregate,
)
core.assign_object(tool.Ifc, tool.Aggregate, tool.Collector, relating_obj=aggregate, related_obj=obj)
tool.Aggregate.constrain_parts_to_aggregate(aggregate)
def create_aggregate(self, context, ifc_class, aggregate_name):
aggregate = bpy.data.objects.new(aggregate_name, None)
+12
View File
@@ -83,3 +83,15 @@ class Aggregate(bonsai.core.tool.Aggregate):
queue.update(new_parts := set(ifcopenshell.util.element.get_parts(element)))
parts.update(new_parts)
return parts
@classmethod
def constrain_parts_to_aggregate(cls, aggregate: ifcopenshell.entity_instance):
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]
for obj in parts_objs:
constraint = next((c for c in obj.constraints if c.type == "CHILD_OF"), None)
if constraint:
obj.constraints.remove(constraint)
constraint = obj.constraints.new("CHILD_OF")
constraint.target = aggregate