diff --git a/src/bonsai/bonsai/bim/module/aggregate/operator.py b/src/bonsai/bonsai/bim/module/aggregate/operator.py index af88e0b767..1bf1dbbbf6 100644 --- a/src/bonsai/bonsai/bim/module/aggregate/operator.py +++ b/src/bonsai/bonsai/bim/module/aggregate/operator.py @@ -23,7 +23,6 @@ import ifcopenshell.util.element import bonsai.tool as tool import bonsai.core.aggregate as core import bonsai.core.spatial -from bonsai.bim.ifc import IfcStore class BIM_OT_aggregate_assign_object(bpy.types.Operator, tool.Ifc.Operator): @@ -104,26 +103,28 @@ class BIM_OT_aggregate_unassign_object(bpy.types.Operator, tool.Ifc.Operator): ifcopenshell.api.run("pset.remove_pset", tool.Ifc.get(), product=element, pset=pset) -class BIM_OT_enable_editing_aggregate(bpy.types.Operator, tool.Ifc.Operator): +class BIM_OT_enable_editing_aggregate(bpy.types.Operator): """Enable editing aggregation relationship""" bl_idname = "bim.enable_editing_aggregate" bl_label = "Enable Editing Aggregate" bl_options = {"REGISTER", "UNDO"} - def _execute(self, context): + def execute(self, context): core.enable_editing_aggregate(tool.Aggregate, obj=context.active_object) + return {"FINISHED"} -class BIM_OT_disable_editing_aggregate(bpy.types.Operator, tool.Ifc.Operator): +class BIM_OT_disable_editing_aggregate(bpy.types.Operator): """Disable editing aggregation relationship""" bl_idname = "bim.disable_editing_aggregate" bl_label = "Disable Editing Aggregate" bl_options = {"REGISTER", "UNDO"} - def _execute(self, context): + def execute(self, context): core.disable_editing_aggregate(tool.Aggregate, obj=context.active_object) + return {"FINISHED"} class BIM_OT_add_aggregate(bpy.types.Operator, tool.Ifc.Operator): @@ -193,9 +194,6 @@ class BIM_OT_select_parts(bpy.types.Operator): obj: bpy.props.StringProperty() def execute(self, context): - self.file = IfcStore.get_file() - # obj = bpy.data.objects.get(self.obj) or context.active_object - for obj in context.selected_objects: parts = ifcopenshell.util.element.get_parts(tool.Ifc.get_entity(obj)) if parts: @@ -225,12 +223,6 @@ class BIM_OT_select_aggregate(bpy.types.Operator): return "Select Aggregate" def execute(self, context): - self.file = IfcStore.get_file() - - # obj = bpy.data.objects.get(self.obj) or context.active_object - # aggregate = ifcopenshell.util.element.get_aggregate(tool.Ifc.get_entity(obj)) - # aggregate_obj = tool.Ifc.get_object(aggregate) - all_parts = [] for obj in context.selected_objects: element = tool.Ifc.get_entity(obj) @@ -311,18 +303,18 @@ class BIM_OT_break_link_to_other_aggregates(bpy.types.Operator, tool.Ifc.Operato pset = tool.Ifc.get().by_id(pset["id"]) ifcopenshell.api.run("pset.remove_pset", tool.Ifc.get(), product=part, pset=pset) - linked_aggregate_group = [ + linked_aggregate_group = next( r.RelatingGroup - for r in getattr(aggregate, "HasAssignments", []) or [] + for r in getattr(aggregate, "HasAssignments", []) if r.is_a("IfcRelAssignsToGroup") if "BBIM_Linked_Aggregate" in r.RelatingGroup.Name - ] - tool.Ifc.run("group.unassign_group", group=linked_aggregate_group[0], products=[aggregate]) + ) + tool.Ifc.run("group.unassign_group", group=linked_aggregate_group, products=[aggregate]) return {"FINISHED"} -class BIM_OT_select_linked_aggregates(bpy.types.Operator, tool.Ifc.Operator): +class BIM_OT_select_linked_aggregates(bpy.types.Operator): bl_idname = "bim.select_linked_aggregates" bl_label = "Select linked aggregates" bl_options = {"REGISTER", "UNDO"} @@ -335,8 +327,7 @@ class BIM_OT_select_linked_aggregates(bpy.types.Operator, tool.Ifc.Operator): else: return "Select all aggregates" - def _execute(self, context): - + def execute(self, context): for obj in context.selected_objects: obj.select_set(False) element = tool.Ifc.get_entity(obj) @@ -346,14 +337,14 @@ class BIM_OT_select_linked_aggregates(bpy.types.Operator, tool.Ifc.Operator): if not element: continue - linked_aggregate_group = [ + linked_aggregate_group = next( r.RelatingGroup - for r in getattr(aggregate, "HasAssignments", []) or [] + for r in getattr(aggregate, "HasAssignments", []) if r.is_a("IfcRelAssignsToGroup") if "BBIM_Linked_Aggregate" in r.RelatingGroup.Name - ] + ) - group_rel = linked_aggregate_group[0].IsGroupedBy or [] + group_rel = linked_aggregate_group.IsGroupedBy for group_link in group_rel: parts = list(group_link.RelatedObjects) if self.select_parts: