0
$\begingroup$

I have loaded an stl file and want to do some boolean stuff on it using python API (see code below). First I create the bevel spline and move the end points where I want them. Then I create a boolean modifier and try to union with the bevel-curve. After that want to subtract the union from a cube to make a hole.

But the curve can't be assigned as the object of the union; not even manually and I don't even get an error. Nothing happens. I can set the surrounding cube as the object and that works fine.

So is there something wrong with using bezier curves in boolean modifiers or am I doing something else wrong.

enter image description here

# ------- Model stuff -------

#bpy.ops.import_mesh.stl(filepath="K:/PQJ/Mold Generator/Blender test/Sphere_Full_40.stl", filter_glob="*.stl", files=[{"name":"Sphere_Full_40.stl", "name":"Sphere_Full_40.stl"}], directory="K:/PQJ/Mold Generator/Blender test")
bpy.ops.import_mesh.stl(filepath="K:/PQJ/Mold Generator/Blender test/898L-OutputModel-SLA[]_09.stl", filter_glob="*.stl", files=[{"name":"898L-OutputModel-SLA[]_09.stl", "name":"898L-OutputModel-SLA[]_09.stl"}], directory="K:/PQJ/Mold Generator/Blender test")
model = bpy.context.active_object


# ------- Mold stuff -------

mold_size = (20,30,30)
mold_displace = (mold_size[0]/2.0,mold_size[1]/2.0,mold_size[2]/2.0)
#mold_displace = (10,10,15)
bpy.ops.mesh.primitive_cube_add(enter_editmode=False, align='WORLD', location=mold_displace, scale=mold_size)
mold = bpy.context.active_object # New objects are selected by default

# ------- In- and outflow stuff -------

bpy.ops.curve.primitive_bezier_curve_add(radius=10, enter_editmode=False, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1))
curve = bpy.context.active_object
bpy.ops.curve.primitive_bezier_circle_add(radius=0.5, enter_editmode=False, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1))
profile = bpy.context.active_object

curve.data.bevel_object = bpy.data.objects["BezierCircle"]

curve.data.splines[0].bezier_points[0].co = (-0.01, mold_size[1]/2, mold_size[2]/2)
curve.data.splines[0].bezier_points[0].handle_left  = (-1, curve.data.splines[0].bezier_points[0].co[1], curve.data.splines[0].bezier_points[0].co[2])
curve.data.splines[0].bezier_points[0].handle_right = ( 1, curve.data.splines[0].bezier_points[0].co[1], curve.data.splines[0].bezier_points[0].co[2])

curve.data.splines[0].bezier_points[1].co = (5,13,10) 
curve.data.splines[0].bezier_points[1].handle_left  = ( 1, curve.data.splines[0].bezier_points[1].co[1], curve.data.splines[0].bezier_points[1].co[2])
curve.data.splines[0].bezier_points[1].handle_right = (-1, curve.data.splines[0].bezier_points[1].co[1], curve.data.splines[0].bezier_points[1].co[2])

# ------- Boolean -------

bool_model = model.modifiers.new(type="BOOLEAN", name="bool mold") # create and store a modifier
bool_model.object = curve
bool_model.operation = 'UNION'
#model.hide_viewport = True

#bool_mold = mold.modifiers.new(type="BOOLEAN", name="bool mold") # create and store a modifier
#bool_mold.object = model
#bool_mold.operation = 'DIFFERENCE'
#model.hide_viewport = True

!!! EDIT: I see the same when I try manually. I find this totally bizarre. I have subtracted large objects from stl with 50000 faces each. So why can't I use bool on a simple bend cylinder? It is even meshed! I just happen to know even more about it than just the mesh. So just forget that it's a curved bevel and just use the mesh.

enter image description here

$\endgroup$

1 Answer 1

0
$\begingroup$

So why can't I use bool on a simple bend cylinder? It is even meshed!

In your screenshot it's not a mesh. You can't use the boolean modifier with a curve object, even if it's beveled. You have to first convert it to a mesh.

bool

I am not a Python developer, so I don't know how to perform that step in code, but that is likely what your problem is.

Edit: Here is another question that has a Python implementation.

$\endgroup$

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.