"""ISO 7380 button head socket screw. Envelope: domed head (revolved profile), hex socket, plain shank. The head's flat side is on the XY plane at the origin; the shank points down -Z.""" from steve import Model size = "M4" # Thread size length = 10 # mm Length under the head # size: (head diameter dk, head height k, hex key s) HEADS = { 'M3': (5.7, 1.65, 2.0), 'M4': (7.6, 2.2, 2.5), 'M5': (9.5, 2.75, 3.0), 'M6': (10.5, 3.3, 4.0), 'M8': (14.0, 4.4, 5.0), 'M10': (17.5, 5.5, 6.0), 'M12': (21.0, 6.6, 8.0), } NOMINAL = { 'M3': 3.0, 'M4': 4.0, 'M5': 5.0, 'M6': 6.0, 'M8': 8.0, 'M10': 10.0, 'M12': 12.0, } dk, k, s = HEADS[size] d = NOMINAL[size] model = Model() with model.sketch("head_profile", on="XZ", name="Head profile") as sk: sk.polyline("outline", [(0, 0), (dk / 2, 0), (dk / 2, 0.25 * k), (0.42 * dk, 0.7 * k), (0.3 * dk, 0.92 * k), (0, k)]) model.revolve("head", "head_profile", axis="Z") with model.sketch("shank_sketch", on="XY", name="Shank") as sk: sk.circle("shank", (0, 0), d / 2) model.extrude("shank", "shank_sketch", distance=-length) model.plane("head_top", on="XY", offset=k, name="Head top") with model.sketch("socket_sketch", on="head_top", name="Hex socket") as sk: sk.polygon("hex", (0, 0), s / 2, 6, inscribed=False) model.extrude("socket", "socket_sketch", distance=-0.6 * k, op="cut") result = model.result()