So currently when using the boolean modifier you have to set the type and then select the object manually.

I am curious how one could automate this like this:

select two objects select Add Boolean Union button

the button will do this: add boolean modifier to active object set type to union select other object as to be unioned to the active object

Ideally the object selection should be done via mouse selection. First click is the tool object and last click is the active object to add the modifier to.

enter image description here enter image description here


1 Answer 1


Modifiers are stored in an object's modifier list and a new one can be added by calling obj.modifers.new(name, type). To adjust the modifier settings you can either collect the created modifier object returned by the new method or access it through the list.

import bpy

target_obj = bpy.data.objects['Cube']
cutter_obj = bpy.data.objects['Sphere']

bool_mod = target_obj.modifiers.new('cutter', 'BOOLEAN')

bool_mod.object = cutter_obj
bool_mod.operation = 'DIFFERENCE'

# or directly -
bpy.data.objects['Cube'].modifiers[0].object = bpy.data.objects['Sphere']
  • $\begingroup$ Wow this works so flawless. How can you define the cutter object via the mouse click similar to how you can select the active object via "target_obj = context.object"? $\endgroup$ Jan 7, 2016 at 16:02
  • $\begingroup$ One way could be to have more than one object selected, use context.active_object as the object to get the modifiers and loop through context.selected_objects while skipping the one that == active_object and add a boolean modifier for each. You may also want to look at the booltool addon $\endgroup$
    – sambler
    Jan 8, 2016 at 14:56

You must log in to answer this question.

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