diff --git a/src/bonsai/bonsai/bim/import_ifc.py b/src/bonsai/bonsai/bim/import_ifc.py index 5417392052..e4c74bbc41 100644 --- a/src/bonsai/bonsai/bim/import_ifc.py +++ b/src/bonsai/bonsai/bim/import_ifc.py @@ -257,7 +257,6 @@ class IfcImporter: self.place_objects_in_collections() self.profile_code("Place objects in collections") self.setup_arrays() - self.setup_aggregates() self.profile_code("Setup arrays") tool.Project.load_linked_models_from_ifc() self.profile_code("Load linked models") @@ -1117,15 +1116,6 @@ class IfcImporter: tool.Blender.Modifier.Array.set_children_lock_state(element, i, True) tool.Blender.Modifier.Array.constrain_children_to_parent(element) - def setup_aggregates(self): - elements = set(self.file.by_type("IfcElement")) - for element in elements: - parts = ifcopenshell.util.element.get_parts(element) - if parts: - relating_obj = tool.Ifc.get_object(element) - if relating_obj: - tool.Aggregate.constrain_all_parts_to_aggregate(relating_obj) - bpy.context.scene.BIMAggregateProperties.aggregate_decorator = True class IfcImportSettings: diff --git a/src/bonsai/bonsai/bim/module/aggregate/operator.py b/src/bonsai/bonsai/bim/module/aggregate/operator.py index 49516d1f82..25cc24a492 100644 --- a/src/bonsai/bonsai/bim/module/aggregate/operator.py +++ b/src/bonsai/bonsai/bim/module/aggregate/operator.py @@ -67,7 +67,6 @@ class BIM_OT_aggregate_assign_object(bpy.types.Operator, tool.Ifc.Operator): relating_obj=relating_obj, related_obj=obj, ) - tool.Aggregate.constrain_part_to_aggregate(obj, relating_obj) props = context.scene.BIMAggregateProperties if relating_obj == props.editing_aggregate and props.in_aggregate_mode: new_editing_obj = props.editing_objects.add() @@ -101,7 +100,6 @@ class BIM_OT_aggregate_unassign_object(bpy.types.Operator, tool.Ifc.Operator): related_obj=tool.Ifc.get_object(element), ) - tool.Aggregate.apply_constraints(tool.Ifc.get_object(element)) # Removes Pset related to Linked Aggregates if not element.is_a("IfcElementAssembly"): @@ -185,7 +183,6 @@ 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_all_parts_to_aggregate(aggregate) def create_aggregate(self, context, ifc_class, aggregate_name): aggregate = bpy.data.objects.new(aggregate_name, None) diff --git a/src/bonsai/bonsai/bim/module/geometry/operator.py b/src/bonsai/bonsai/bim/module/geometry/operator.py index 5a492715b0..19e15a2f01 100644 --- a/src/bonsai/bonsai/bim/module/geometry/operator.py +++ b/src/bonsai/bonsai/bim/module/geometry/operator.py @@ -2931,7 +2931,7 @@ class OverrideMoveAggregateMacro(bpy.types.Macro): class OverrideMoveAggregate(bpy.types.Operator): bl_idname = "bim.override_move_aggregate" - bl_label = "IFC Move Aggregate" + bl_label = "IFC Move" bl_options = {"REGISTER", "UNDO"} @classmethod @@ -2971,5 +2971,9 @@ class OverrideMoveAggregate(bpy.types.Operator): aggregates_to_move = set(aggregates_to_move) for obj in aggregates_to_move: obj.select_set(True) + if parts := ifcopenshell.util.element.get_parts(tool.Ifc.get_entity(obj)): + for part in parts: + part_obj = tool.Ifc.get_object(part) + part_obj.select_set(True) self.new_active_obj = obj return {"FINISHED"} diff --git a/src/bonsai/bonsai/tool/aggregate.py b/src/bonsai/bonsai/tool/aggregate.py index a19c4a2f40..8612e61689 100644 --- a/src/bonsai/bonsai/tool/aggregate.py +++ b/src/bonsai/bonsai/tool/aggregate.py @@ -84,66 +84,6 @@ class Aggregate(bonsai.core.tool.Aggregate): parts.update(new_parts) return parts - @classmethod - def constrain_all_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] - for obj in parts_objs: - constraint = next((c for c in obj.constraints if c.type == "CHILD_OF"), None) - if constraint: - try: - bpy.context.view_layer.objects.active = obj - bpy.ops.constraint.apply(constraint="Child Of") - except: - pass - constraint = obj.constraints.new("CHILD_OF") - constraint.target = aggregate - - @classmethod - def constrain_part_to_aggregate(cls, part: bpy.types.Object, aggregate: bpy.types.Object): - constraint = next((c for c in part.constraints if c.type == "CHILD_OF"), None) - if constraint: - try: - bpy.context.view_layer.objects.active = obj - bpy.ops.constraint.apply(constraint="Child Of") - except: - pass - constraint = part.constraints.new("CHILD_OF") - constraint.target = aggregate - - if bpy.context.scene.BIMAggregateProperties.in_aggregate_mode: - constraint.enabled = False - - @classmethod - def apply_constraints(cls, part: bpy.types.Object): - constraint = next((c for c in part.constraints if c.type == "CHILD_OF"), None) - if constraint: - bpy.context.view_layer.objects.active = part - bpy.ops.constraint.apply(constraint=constraint.name) - - @classmethod - def disable_constraints(cls, objs: list[bpy.types.Object]): - # Disable constraints while keeping parts in the same location - for obj in objs: - matrix = obj.matrix_world.copy() - constraint = next((c for c in obj.constraints if c.type == "CHILD_OF"), None) - if constraint: - constraint.enabled = False - obj.matrix_world = matrix - - @classmethod - def enable_constraints(cls, objs: list[bpy.types.Object]): - # Enable constraints while keeping parts in the same location - for obj in objs: - constraint = next((c for c in obj.constraints if c.type == "CHILD_OF"), None) - if constraint: - constraint.enabled = True - bpy.context.view_layer.update() - for obj in objs: - diff = obj.matrix_world.translation - obj.location - obj.location -= diff - @classmethod def get_aggregate_mode(cls): return bpy.context.scene.BIMAggregateProperties.in_aggregate_mode @@ -182,7 +122,6 @@ class Aggregate(bonsai.core.tool.Aggregate): editing_obj = props.editing_objects.add() editing_obj.obj = obj.original - tool.Aggregate.disable_constraints([o.obj for o in props.editing_objects]) props.in_aggregate_mode = True return {"FINISHED"} @@ -200,7 +139,6 @@ class Aggregate(bonsai.core.tool.Aggregate): parts = ifcopenshell.util.element.get_parts(tool.Ifc.get_entity(props.editing_aggregate)) objs = [tool.Ifc.get_object(part) for part in parts] - tool.Aggregate.enable_constraints(objs) if context.space_data.local_view: bpy.ops.view3d.localview() diff --git a/src/bonsai/bonsai/tool/root.py b/src/bonsai/bonsai/tool/root.py index fad01245dd..12b39a215f 100644 --- a/src/bonsai/bonsai/tool/root.py +++ b/src/bonsai/bonsai/tool/root.py @@ -341,7 +341,6 @@ class Root(bonsai.core.tool.Root): ) continue - tool.Aggregate.apply_constraints(tool.Ifc.get_object(new[0])) bonsai.core.aggregate.assign_object( tool.Ifc, tool.Aggregate, @@ -363,7 +362,6 @@ class Root(bonsai.core.tool.Root): related_obj=tool.Ifc.get_object(tool.Ifc.get_entity(obj)), ) - tool.Aggregate.constrain_all_parts_to_aggregate(tool.Ifc.get_object(new_aggregate[0])) tool.Blender.select_and_activate_single_object(bpy.context, tool.Ifc.get_object(new_aggregate[0])) @classmethod