4
$\begingroup$

If i have a cube A and sphere B. I apply boolean modifier (difference) to A and use B as cutter. So B is 'linked' to A via boolean modifier but B is not a child of A.

When A is selected , is there a method to select all of its cutters ?

$\endgroup$
3
  • 1
    $\begingroup$ I don't think so, you need to parent them or put them in the same collection then select one of them and Shift G > Collection $\endgroup$
    – moonboots
    Commented Nov 17, 2020 at 7:39
  • $\begingroup$ I don't think so either, if you want to select a single cutter object, you can right-click it in the modifier and choose "Jump to Target", then this cutter is selected. But that doesn't work with multiple Boolean modifiers. $\endgroup$ Commented Nov 17, 2020 at 8:15
  • $\begingroup$ Oh, and of course if the cutter is disabled in viewport so that you can see the effect without having it blocking the view, the "Jump to Target" option won't work neither, since disabled objects won't be selected. So arranging them in a collection like moonboots suggested would be the best way if you don't want to parent them to the main object. $\endgroup$ Commented Nov 17, 2020 at 8:22

1 Answer 1

6
$\begingroup$

Here's a script that adds an operator to do that in the "Select" menu.

I added 3 checkboxes to specifiy if you want to include hidden (eye icon), disabled (monitor icon) or unselectable objects, since by default they can't be selected if they are in either of these states.

The operator selects everything by default, hidden, selectable or not.

import bpy


class SelectBooleansOperator(bpy.types.Operator):
    bl_label = "Select Linked Booleans"
    bl_idname = "object.select_linked_booleans"
    bl_options = {'REGISTER', 'UNDO'}
    
    extend: bpy.props.BoolProperty(
        name="Extend",
        default=False,
        )
        
    select_hidden: bpy.props.BoolProperty(
        name="Select Hidden",
        default=True,
        )
        
    select_disabled: bpy.props.BoolProperty(
        name="Select Disabled",
        default=True,
        )
    
    select_unselectable: bpy.props.BoolProperty(
        name="Select Unselectable",
        default=True,
        )
    
    @classmethod
    def poll(cls, context):
        return context.active_object and context.active_object.type == 'MESH'

    def execute(self, context):
        layout = self.layout
        
        mods = context.active_object.modifiers
        
        for mod in mods:
            if mod.type != 'BOOLEAN':
                continue
            
            obj = mod.object
            
            # Logic from https://blenderartists.org/t/blender-2-8-python-hide-unhide-objects/1141228/2
            
            if (not obj.hide_viewport and not obj.visible_get()) and self.select_hidden: 
                # Hidden with the eye icon
                obj.hide_set(False)
                
            if obj.hide_viewport:
                obj.hide_viewport = False #  Toggle to test visibility
            
                if obj.visible_get() and self.select_disabled:
                    # Hidden with the monitor icon
                    obj.hide_viewport = False              
                elif self.select_disabled and self.select_hidden:
                    # Hidden both ways
                    obj.hide_viewport = False
                    obj.hide_set(False)
                else:
                    obj.hide_viewport = True #  Toggle back          
                        
            if obj.hide_select and self.select_unselectable:
                obj.hide_select = False
            
            mod.object.select_set(True)
            
        context.active_object.select_set(self.extend)
        
        return {'FINISHED'}

def draw_item(self, context):
    self.layout.operator(SelectBooleansOperator.bl_idname)


def register():
    bpy.utils.register_class(SelectBooleansOperator)
    bpy.types.VIEW3D_MT_select_object.append(draw_item)


def unregister():
    bpy.utils.unregister_class(SelectBooleansOperator)
    bpy.types.VIEW3D_MT_select_object.remove(draw_item)


if __name__ == "__main__":
    register()

How to use :

How to run a script

enter image description here

Note that you would have to re-run the script every time you close and open Blender. If you want it to be persistent, make it into an add-on.

You can also add a shortcut to the operator by right clicking it in the menu.

$\endgroup$
4
  • $\begingroup$ Thanks , it works great, just 1 more question : Because i turn off 'selectable' of my Boolean obj (cutter), running the script won't select them in 3d view. How about to make them selected in outliner, so even they're invisible, it can still be highlighted in outliner ? $\endgroup$
    – andio
    Commented Nov 17, 2020 at 10:59
  • $\begingroup$ I updated the code, it is not exactly as you asked because the visibility logic is a bit too obscure for me between the areas, so the objects will get un-hidden in the viewport if you try to select them $\endgroup$
    – Gorgious
    Commented Nov 17, 2020 at 13:29
  • $\begingroup$ Sorry I glanced a bit too fast over your comment. It will get selectable after running the operator $\endgroup$
    – Gorgious
    Commented Nov 17, 2020 at 20:27
  • $\begingroup$ Great. it's perfect for my need. Thanks a lot. $\endgroup$
    – andio
    Commented Nov 18, 2020 at 15:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .