"""Hex standoffs (spacers) M2 to M4, female/female and male/female: Würth WA-SBRII / WA-SBRIE (M2) and Harwin R25/R30/R40-100 (female/female) and -300 (male/female) (M2.5, M3, M4). A hex prism, width across flats AF (the maker's maximum), corners along X, from z = 0 to the body length L, centred on the origin. Internal threads are drawn as bores at the nominal diameter to the maker's (minimum full) thread length (through where the maker's part is tapped through; from both ends of a female/female standoff); the male stud, at the nominal diameter, runs from z = 0 down by its length. Threads, chamfers and the stud's undercut are not modelled. """ from steve import Model thread = "M3" # Thread gender = "female-female" # Gender length = 10 # mm Body length L material = "brass-nickel" # Material NOMINAL = {"M2": 2.0, "M2.5": 2.5, "M3": 3.0, "M4": 4.0} # (thread, gender): (maker series, across flats AF, stud length, [(up to body length, female thread length)]) # female thread length None = tapped through. SERIES = { ("M2", "female-female"): ("Würth WA-SBRII", 4.0, 0, [(15, None)]), ("M2", "male-female"): ("Würth WA-SBRIE", 4.0, 5.0, [(5, 2.5), (10, 5.0), (30, 6.0)]), ("M2.5", "female-female"): ("Harwin R25-100", 5.0, 0, [(20, None), (33, 10.0)]), ("M2.5", "male-female"): ("Harwin R25-300", 5.0, 5.0, [(3, 1.9), (5, 2.5), (6, 3.5), (7, 4.5), (20, 5.0)]), ("M3", "female-female"): ("Harwin R30-100", 5.0, 0, [(21, None), (40, 10.0)]), ("M3", "male-female"): ("Harwin R30-300", 5.0, 6.0, [(4, 2.0), (5, 2.5), (6, 3.0), (7, 4.5), (8, 5.5), (80, 6.0)]), ("M4", "female-female"): ("Harwin R40-100", 7.0, 0, [(21, None), (60, 10.0)]), ("M4", "male-female"): ("Harwin R40-300", 7.0, 8.0, [(6, 2.5), (7, 3.5), (8, 4.5), (9, 5.5), (10, 6.5), (63, 8.0)]), } MATERIALS = {"brass-nickel": ("brass", "#c6c8c4")} series, AF, stud, depths = SERIES[(thread, gender)] d = NOMINAL[thread] depth = next((t for upto, t in depths if length <= upto), depths[-1][1]) material_id, colour = MATERIALS[material] model = Model() with model.sketch("body_sketch", on="XY", name="Body") as sk: sk.polygon("hex", (0, 0), AF / 2, 6, inscribed=False) model.extrude("body", "body_sketch", distance=length, name="Body") if depth is None: model.cylinder("bore", d / 2, length, op="cut", name="Thread") else: model.cylinder("top_thread", d / 2, depth, at=(0, 0, length - depth), op="cut", name="Top thread") if gender == "female-female": model.cylinder("bottom_thread", d / 2, depth, op="cut", name="Bottom thread") if gender == "male-female": model.cylinder("stud", d / 2, stud, at=(0, 0, -stud), op="join", name="Stud") model.material(material_id, color=colour) result = model.result()