Skip to content

Instantly share code, notes, and snippets.

@openroomxyz
Created April 16, 2020 11:12
Show Gist options
  • Select an option

  • Save openroomxyz/f790b1037cd2ffdf6b936e906d232a78 to your computer and use it in GitHub Desktop.

Select an option

Save openroomxyz/f790b1037cd2ffdf6b936e906d232a78 to your computer and use it in GitHub Desktop.
Blender Python : How to get Boolean Union of two objects?
import bpy
def Union(name_a, name_b, new_one_name):
# Create a boolean modifier named 'my_bool_mod' for the cube.
mod_bool = bpy.data.objects[name_a].modifiers.new('my_bool_mod', 'BOOLEAN')
# Set the mode of the modifier to DIFFERENCE.
mod_bool.operation = 'UNION' #'DIFFERENCE'
# Set the object to be used by the modifier.
mod_bool.object = bpy.data.objects[name_b]
bpy.context.view_layer.objects.active = bpy.data.objects[name_a]
# Apply the modifier.
res = bpy.ops.object.modifier_apply(apply_as='DATA', modifier = 'my_bool_mod')
bpy.data.objects[name_b].select_set(True) # 2.8+
bpy.ops.object.delete()
bpy.data.objects[name_a].name = new_one_name
return res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment