From 8574057340679969f388eb3ac9617dbc24811fcb Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Thu, 12 Dec 2024 17:44:48 +0500 Subject: [PATCH] bim.hide_booleans to hide all selected booleans, not just active short demo - https://imgur.com/a/1h2glfj --- src/bonsai/bonsai/bim/module/model/opening.py | 22 ++++++++++++------- src/bonsai/bonsai/tool/model.py | 4 ++++ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/model/opening.py b/src/bonsai/bonsai/bim/module/model/opening.py index 9c081a004b..a24c18e376 100644 --- a/src/bonsai/bonsai/bim/module/model/opening.py +++ b/src/bonsai/bonsai/bim/module/model/opening.py @@ -707,7 +707,7 @@ class HideBooleans(Operator, tool.Ifc.Operator): bl_label = "Hide Booleans" bl_description = ( "Hide boolean objects and apply their changed transforms.\n" - "If boolean object is active, hide it, otherwise hide all boolean objects" + "If boolean object is selected, hide it, otherwise hide all boolean objects" ) bl_options = {"REGISTER", "UNDO"} @@ -716,12 +716,18 @@ class HideBooleans(Operator, tool.Ifc.Operator): unit_scale = ifcopenshell.util.unit.calculate_unit_scale(ifc_file) builder = ifcopenshell.util.shape_builder.ShapeBuilder(ifc_file) - set_active_obj = None + set_active_obj, set_selected_objs = None, None boolean_objs: list[bpy.types.Object] - active_boolean_obj = (obj := context.active_object) and tool.Model.is_boolean_obj(obj) - if active_boolean_obj: - boolean_objs = [obj] - set_active_obj = obj.data.BIMMeshProperties.obj + selected_objects = tool.Blender.get_selected_objects() + selected_booleans_objs = [obj for obj in selected_objects if tool.Model.is_boolean_obj(obj)] + if selected_booleans_objs: + boolean_objs = selected_booleans_objs + if (active_object := context.active_object) in selected_booleans_objs: + active_obj_source = active_object + else: + active_obj_source = selected_booleans_objs[0] + set_active_obj = active_obj_source.data.BIMMeshProperties.obj + set_selected_objs = [tool.Model.get_booleaned_obj(obj) for obj in boolean_objs] else: props = bpy.context.scene.BIMModelProperties boolean_objs = [obj for o in props.openings if (obj := o.obj)] @@ -754,8 +760,8 @@ class HideBooleans(Operator, tool.Ifc.Operator): bpy.data.objects.remove(obj) tool.Model.clear_scene_openings() - if set_active_obj: - tool.Blender.set_active_object(set_active_obj) + if set_active_obj and set_selected_objs is not None: + tool.Blender.set_objects_selection(context, set_active_obj, set_selected_objs) return {"FINISHED"} diff --git a/src/bonsai/bonsai/tool/model.py b/src/bonsai/bonsai/tool/model.py index 6a50090af5..4d5b573f7a 100644 --- a/src/bonsai/bonsai/tool/model.py +++ b/src/bonsai/bonsai/tool/model.py @@ -1902,3 +1902,7 @@ class Model(bonsai.core.tool.Model): @classmethod def is_boolean_obj(cls, obj: bpy.types.Object) -> bool: return obj.type == "MESH" and obj.data.BIMMeshProperties.ifc_boolean_id + + @classmethod + def get_booleaned_obj(cls, boolean_obj: bpy.types.Object) -> bpy.types.Object: + return boolean_obj.data.BIMMeshProperties.obj