import cadquery as cq from cadquery.occ_impl.exporters import ExportTypes from ocp_vscode import show, show_object import math ###### Parameter ##### a_thick = 1.7 a_diam = 2.4 a_gap_width = 0.8 overhang_a_width = a_gap_width /2 * 0.85 overhang_a_height = 3 b_thick = 4.2 b_diam = 3.1 b_gap_width = a_gap_width overhang_b_width = b_gap_width /2 * 0.9 overhang_b_height = overhang_a_height thick_eps = 0.1 space_height = 2 space_diam = 7 overhang_top = 0.5 cut_height = 2.8 # use this for easier printing cut_center = False # if false, cut is at the edge of smallest diameter of the spacer spacer = cq.Workplane("XY").cylinder(space_height, space_diam/2) clip_a = ( spacer.faces(">Z").workplane() .circle(a_diam/2-thick_eps).extrude(a_thick, combine=False) .faces(">Z").workplane() .circle(a_diam/2+overhang_a_width).workplane(offset=overhang_a_height+thick_eps) .circle(overhang_top).loft() .faces(">Z").workplane() .rect(a_gap_width, 100) .cutThruAll() ) clip_b = ( spacer.faces(" 0: if cut_center: spacer_cut = spacer.cut(cq.Workplane("XY").box(100, cut_height, 100)) else: min_diam = min(a_diam, b_diam) - 2*thick_eps min_gap_width = min(a_gap_width, b_gap_width) center_to_min_edge = math.sqrt(min_diam**2 - (min_gap_width)**2)/2 spacer_cut = spacer.cut(cq.Workplane("XY").box(100, cut_height, 100, centered=(True, False, True)).translate((0, -center_to_min_edge, 0))) spacer = spacer.cut(spacer_cut) ############ show_object(spacer) with open(r"spacer_2.5.step", "w") as fp: cq.exporters.exportShape(spacer, ExportTypes.STEP, fp)