import bpy # clear the screen by deleting all existing objects bpy.ops.object.select_all(action='SELECT') bpy.ops.object.delete(use_global=False) ################## # make a base clamp x = 16 y = 40 z = 27 bpy.ops.mesh.primitive_cube_add(size=1, location=(0,0,0)) part = bpy.context.active_object part.scale = x, y, z part.location[2] += 0 ################### # clear the flanks x = 18 y = 20 z = 27 bpy.ops.mesh.primitive_cube_add(size=1, location=(0,0,0)) flank = bpy.context.active_object flank.scale = x, y, z flank.location[1] += 20 flank.location[2] += 4.3 bcut = part.modifiers.new(type="BOOLEAN", name="bool") bcut.object = flank bcut.operation = 'DIFFERENCE' bpy.context.view_layer.objects.active = part bpy.ops.object.modifier_apply(apply_as='DATA', modifier='bool') flank.location[1] -= 40 bcut = part.modifiers.new(type="BOOLEAN", name="bool") bcut.object = flank bcut.operation = 'DIFFERENCE' bpy.context.view_layer.objects.active = part bpy.ops.object.modifier_apply(apply_as='DATA', modifier='bool') bpy.ops.object.delete() ################################### # make the cylinder for post d = 12.9 l = 30 bpy.ops.mesh.primitive_cylinder_add(vertices=64, location=(0,0,0), radius=.5) cyl = bpy.context.active_object cyl.scale = d,d,l cyl.rotation_euler[1] = 3.14159/2 cyl.location[2] += 0 # cut the cylinder out of the base part bcut = part.modifiers.new(type="BOOLEAN", name="bool") bcut.object = cyl bcut.operation = 'DIFFERENCE' bpy.context.view_layer.objects.active = part bpy.ops.object.modifier_apply(apply_as='DATA', modifier='bool') bpy.context.view_layer.objects.active = cyl bpy.ops.object.delete() ################## # make a slit for clamping x = 20 y = 1.2 z = 20 bpy.ops.mesh.primitive_cube_add(size=1, location=(0,0,0)) slit = bpy.context.active_object slit.scale = x, y, z slit.location[2] += 10 bcut = part.modifiers.new(type="BOOLEAN", name="bool") bcut.object = slit bcut.operation = 'DIFFERENCE' bpy.context.view_layer.objects.active = part bpy.ops.object.modifier_apply(apply_as='DATA', modifier='bool') bpy.context.view_layer.objects.active = slit bpy.ops.object.delete() bolt_height = 9 ################################### # make the cylinder for bolt shaft d = 4.5 l = 30 bpy.ops.mesh.primitive_cylinder_add(vertices=64, location=(0,0,0), radius=.5) cyl = bpy.context.active_object cyl.scale = d,d,l cyl.rotation_euler[0] = 3.14159/2 cyl.location[2] += bolt_height # cut the cylinder out of the base part bcut = part.modifiers.new(type="BOOLEAN", name="bool") bcut.object = cyl bcut.operation = 'DIFFERENCE' bpy.context.view_layer.objects.active = part bpy.ops.object.modifier_apply(apply_as='DATA', modifier='bool') bpy.context.view_layer.objects.active = cyl bpy.ops.object.delete() ################################### # make the cylinder for bolt head d = 7.8 l = 6 bpy.ops.mesh.primitive_cylinder_add(vertices=64, location=(0,0,0), radius=.5) cyl = bpy.context.active_object cyl.scale = d,d,l/2 cyl.rotation_euler[0] = 3.14159/2 cyl.location[2] += bolt_height cyl.location[1] += -8.5 # cut the cylinder out of the base part bcut = part.modifiers.new(type="BOOLEAN", name="bool") bcut.object = cyl bcut.operation = 'DIFFERENCE' bpy.context.view_layer.objects.active = part bpy.ops.object.modifier_apply(apply_as='DATA', modifier='bool') bpy.context.view_layer.objects.active = cyl bpy.ops.object.delete() ################################### # make the cylinder for nut d = 8.3 l = 3.5 bpy.ops.mesh.primitive_cylinder_add(vertices=6, location=(0,0,0), radius=.5) cyl = bpy.context.active_object cyl.scale = d,d,l/2 cyl.rotation_euler[0] = 3.14159/2 cyl.location[2] += bolt_height cyl.location[1] += 8.4 cyl.rotation_euler[1] = 30*3.14159/180 # cut the cylinder out of the base part bcut = part.modifiers.new(type="BOOLEAN", name="bool") bcut.object = cyl bcut.operation = 'DIFFERENCE' bpy.context.view_layer.objects.active = part bpy.ops.object.modifier_apply(apply_as='DATA', modifier='bool') bpy.context.view_layer.objects.active = cyl bpy.ops.object.delete() ################################### # make the cylinder for bolt shafts d = 4.5 l = 40 yloc = 15 bpy.ops.mesh.primitive_cylinder_add(vertices=64, location=(0,0,0), radius=.5) cyl = bpy.context.active_object cyl.scale = d,d,l/2 #cyl.rotation_euler[1] = 3.14159/2 cyl.location[1] += yloc ## cut the cylinder out of the base part bcut = part.modifiers.new(type="BOOLEAN", name="bool") bcut.object = cyl bcut.operation = 'DIFFERENCE' bpy.context.view_layer.objects.active = part bpy.ops.object.modifier_apply(apply_as='DATA', modifier='bool') bpy.context.view_layer.objects.active = cyl # move it over and cut again cyl.location[1] -= 2*yloc bcut = part.modifiers.new(type="BOOLEAN", name="bool") bcut.object = cyl bcut.operation = 'DIFFERENCE' bpy.context.view_layer.objects.active = part bpy.ops.object.modifier_apply(apply_as='DATA', modifier='bool') bpy.context.view_layer.objects.active = cyl bpy.ops.object.delete() ################################### # make the cylinder for side nuts d = 8.3 l = 30 bpy.ops.mesh.primitive_cylinder_add(vertices=6, location=(0,0,0), radius=.5) cyl = bpy.context.active_object cyl.scale = d,d,l/2 cyl.rotation_euler[2] = 30*3.14159/180 cyl.location[1] += yloc cyl.location[2] += 3 ## cut the cylinder out of the base part bcut = part.modifiers.new(type="BOOLEAN", name="bool") bcut.object = cyl bcut.operation = 'DIFFERENCE' bpy.context.view_layer.objects.active = part bpy.ops.object.modifier_apply(apply_as='DATA', modifier='bool') bpy.context.view_layer.objects.active = cyl # move it over and cut again cyl.location[1] -= 2*yloc bcut = part.modifiers.new(type="BOOLEAN", name="bool") bcut.object = cyl bcut.operation = 'DIFFERENCE' bpy.context.view_layer.objects.active = part bpy.ops.object.modifier_apply(apply_as='DATA', modifier='bool') bpy.context.view_layer.objects.active = cyl bpy.ops.object.delete() part.rotation_euler[1] = 3.14159/2 part.select_set(True) bpy.ops.export_mesh.stl("EXEC_DEFAULT", filepath='/home/jamie/docs/lab/3d_parts/mirror_holder/mirror_holder_clamp.stl' ,use_selection=True)