"""Socket head cap screw, ISO 4762 (DIN 912), M1.6 to M64, any length. Envelope model for assemblies: cylindrical head (largest plain-head diameter dk max, height k max), hexagon socket (nominal key size s, depth t min) and a plain shank at the nominal thread diameter d (the thread is not modelled). The head's bearing face is on the XY plane at the origin, the head above it, the shank along -Z; `length` is the nominal length l, measured from under the head. """ from steve import Model size = "M3" # Thread size length = 10 # mm Nominal length (under the head) material = "steel" # Material # ISO 4762:2004, Table 1 (official preview p. 4, M1.6-M12: # https://cdn.standards.iteh.ai/samples/34460/06335046afaf46fb8e84d91a3eda001d/ISO-4762-2004.pdf; all sizes: # https://fasten.it/en/Norms/Norm/DIN%20EN%20ISO%204762, DIN EN ISO 4762:2004-06). size: (thread d, head diameter dk max, head height k max, hexagon socket s, socket depth t min) DIMENSIONS = { "M1.6": (1.6, 3.0, 1.6, 1.5, 0.7), "M2": (2.0, 3.8, 2.0, 1.5, 1.0), "M2.5": (2.5, 4.5, 2.5, 2.0, 1.1), "M3": (3.0, 5.5, 3.0, 2.5, 1.3), "M4": (4.0, 7.0, 4.0, 3.0, 2.0), "M5": (5.0, 8.5, 5.0, 4.0, 2.5), "M6": (6.0, 10.0, 6.0, 5.0, 3.0), "M8": (8.0, 13.0, 8.0, 6.0, 4.0), "M10": (10.0, 16.0, 10.0, 8.0, 5.0), "M12": (12.0, 18.0, 12.0, 10.0, 6.0), "M14": (14.0, 21.0, 14.0, 12.0, 7.0), "M16": (16.0, 24.0, 16.0, 14.0, 8.0), "M20": (20.0, 30.0, 20.0, 17.0, 10.0), "M24": (24.0, 36.0, 24.0, 19.0, 12.0), "M30": (30.0, 45.0, 30.0, 22.0, 15.5), "M36": (36.0, 54.0, 36.0, 27.0, 19.0), "M42": (42.0, 63.0, 42.0, 32.0, 24.0), "M48": (48.0, 72.0, 48.0, 36.0, 28.0), "M56": (56.0, 84.0, 56.0, 41.0, 34.0), "M64": (64.0, 96.0, 64.0, 46.0, 38.0), } # material choice: (STEVE material library id, appearance colour) MATERIALS = { "steel": ("steel-generic", "#2b2d30"), # property class 8.8 / 10.9 / 12.9, black oxide finish "stainless-a2": ("stainless-304", "#c9ccd0"), # ISO 3506-1 A2-70 "stainless-a4": ("stainless-316", "#c9ccd0"), # ISO 3506-1 A4-70 / A4-80 } d, dk, k, s, t = DIMENSIONS[size] material_id, colour = MATERIALS[material] model = Model() with model.sketch("head_sketch", on="XY", name="Head") as sk: sk.circle("head_circle", (0, 0), dk / 2) model.extrude("head", "head_sketch", distance=k, name="Head") with model.sketch("shank_sketch", on="XY", name="Shank") as sk: sk.circle("shank_circle", (0, 0), d / 2) model.extrude("shank", "shank_sketch", distance=-length, name="Shank") model.plane("head_top", on="XY", offset=k, name="Head top") with model.sketch("socket_sketch", on="head_top", name="Hexagon socket") as sk: sk.polygon("hex", (0, 0), s / 2, 6, inscribed=False) model.extrude("socket", "socket_sketch", distance=-t, op="cut", name="Socket") model.material(material_id, color=colour) result = model.result()