"""ISO 4762 (DIN 912) socket head cap screw. Envelope: head, hex socket and plain shank (no modelled thread). The head sits on the XY plane at the origin; the shank points down -Z. `length` is measured under the head. Material: property class 12.9 alloy steel, quenched and tempered (34CrNiMo6 from the material library), black oxide.""" from steve import Model size = "M3" # Thread size length = 10 # mm Length under the head # size: (head diameter dk, head height k, hex key s) HEADS = { 'M2': (3.8, 2.0, 1.5), 'M2.5': (4.5, 2.5, 2.0), 'M3': (5.5, 3.0, 2.5), 'M4': (7.0, 4.0, 3.0), 'M5': (8.5, 5.0, 4.0), 'M6': (10.0, 6.0, 5.0), 'M8': (13.0, 8.0, 6.0), 'M10': (16.0, 10.0, 8.0), 'M12': (18.0, 12.0, 10.0), } NOMINAL = { 'M2': 2.0, 'M2.5': 2.5, '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_sketch", on="XY", name="Head") as sk: sk.circle("head", (0, 0), dk / 2) model.extrude("head", "head_sketch", distance=k) 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.55 * k, op="cut") model.material("steel-34crnimo6") # class 12.9 alloy steel model.appearance(color="#2e3034", metalness=0.75, roughness=0.38) # black oxide finish result = model.result()