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.
- 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