I'm a newbie in blender and I'm trying to play around with the boolean difference modifier.

I have two concentric disks and I want to perform the boolean differece between them. I'm using the python API.

Here is an example:

import bpy
import bmesh

c1mesh = bpy.data.meshes.new("Disk1")
c1object = bpy.data.objects.new("Disk1", c1mesh)
bm = bmesh.new()
bmesh.ops.create_circle(bm, cap_ends=True, diameter=2, segments=128)

c2mesh = bpy.data.meshes.new("Disk2")
c2object = bpy.data.objects.new("Disk2", c2mesh)
bm = bmesh.new()
bmesh.ops.create_circle(bm, cap_ends=True, diameter=1, segments=128)  

bool = c1object.modifiers.new(type='BOOLEAN', name = "diff1")
bool.operation = 'DIFFERENCE'
bool.object = c2object
c2object.hide = True

This has no effect (besides hiding the second disk). When I try to apply the modifier from the gui I get no result (besides some weird lines over the disk 1).

I guess that the problem is just my poor initial knowledge of blender (and general 3D modelling).

Thanks in advance.


Hope this helps:

import bpy

# initialize the variables to work with, in this case two selected objects, in yours c1mesh and c2mesh
first_object = bpy.context.selected_objects[0]
second_object = bpy.context.selected_objects[1]

# add the modifier and change settings
first_object.modifiers.new(name = "Boolean", type = 'BOOLEAN')
first_object.modifiers.get("Boolean").operation = "DIFFERENCE"
first_object.modifiers.get("Boolean").object = second_object

# just cosmetic hiding of second object so you can instantly see the result
second_object.hide_viewport = True
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.