# Boolean slow: looking for speedup ideas

I have a Python script that takes a mesh (created from an SVG path) and drills holes in it from coordinates in a file.

The whole project is auto-generating models of PCBs I design - but I am only concerned with the generation of the actual PCB at the moment.

My script all works perfectly - it's just that it's horribly, horribly, slow. The slow part is when it's performing boolean operations to cut cylinders out of the mesh.

This is the routine I am using to cut one hole out from the mesh:

def drill(target, x, y, size):
print("Drilling " + str(x) + "," + str(y) + " @ " + str(size) + "mm")
bpy.ops.mesh.primitive_cylinder_add(vertices=64, radius=size/2, depth=10, location=(x, y, 0))
newbit = bpy.context.object
bpy.ops.object.select_all(action='DESELECT')
target.select = True
bpy.context.scene.objects.active = target
bpy.ops.object.modifier_add(type='BOOLEAN')
mod = target.modifiers.new("Drill", type='BOOLEAN')
mod.operation = 'DIFFERENCE'
mod.object = newbit
bpy.context.scene.update()
target.data = target.to_mesh(bpy.context.scene, True, 'PREVIEW')
target.modifiers.remove(mod)
bpy.data.objects.remove(newbit)
#bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)


Yes, I iterate the file getting the data and drill one hole at a time. Originally I was creating multiple "drill bits" then .join()ing them into a single compound object and using that for the boolean operation. This was considerably faster, however often the boolean operation would mess up and the resultant mesh would be a complete mess with faces covering random holes (Blender 2.79b), and the only way I found to cure that was to drill each hole separately.

But the actual drilling operation takes a long time. If you uncomment the last line you can see each hole being cut in turn and see how long it's taking, and it's ages.

So I'm looking for other ideas. Other approaches that I could take to create the mesh - from people that know a darn sight more about Blender than I do.

The constraints:

• There is an SVG file which is used to create the "outline" of a solid mesh that is extruded to give it depth and all faces closed to make it solid.
• There is a list of coordinates and diameters
• The results must not cause incorrect faces to be created

So... ideas?

• 1 Don't convert curves to mesh (it is destructive). 2 Don't use Booleans (produces errors, bad topology, it is slow and fails often); 3 Instead keep the original curve and add bezier circles centered at the correct positions, then join them to the main SVG curve – Duarte Farrajota Ramos Jan 28 at 0:07
• Interesting. So stick as a path / curve and add the holes to it, and then extrude it to a mesh? – Majenko Jan 28 at 0:08
• Curves can be extruded/beveled natively, no need to convert to mesh unless strictly necessary. Try to keep your workflow as non destructive as possible. – Duarte Farrajota Ramos Jan 28 at 0:11
• How would this work with the faces having holes in them? How does it know the circles are holes? – Majenko Jan 28 at 0:18
• All circles would then have to joined back into the main curve, they can't remain as separate objects – Duarte Farrajota Ramos Jan 28 at 0:22

## 1 Answer

Booleans are slow, heavy, error prone and produce bad topology, they also only work on meshes, requiring conversion of curves to mesh which is a destructive process.

I would suggest instead a different approach. Keep you SVG import as a live bezier curve object, use its builtin extrusion and beveling capabilities to generate geometry.

Then use the coordinates file to create bezier curve circle objects with the desired radius at the correct positions. Join these created circles back into the original SVG object. Set it as 2D curve.

If everything has been correctly designed as coherent closed splines, Blender should be able to correctly close them and represent the circles as holes.

• It kind of works. For a simple curve with only a few holes it's fine. For a more complex one with hundreds / thousands of holes it gets confused. – Majenko Jan 28 at 10:33
• Actually you can ignore that. Having two holes in the same location confuses Blender. I have fixed it by filtering my holes so it's impossible to have two at the same place. – Majenko Jan 28 at 11:38