"""Hexagon socket countersunk head screw, ISO 10642 (DIN 7991), M3 to M12, any length. Envelope model for assemblies: 90 degree countersunk head (the cone of the theoretical sharp-edge diameter dk th and height k, its rim turned to the actual head diameter dk min, so it sits in a countersink exactly as the standard intends), hexagon socket (key size s, depth t min) and a plain shank at the nominal thread diameter d (the thread is not modelled). The head's top face is on the XY plane at the origin, the screw along -Z; `length` is the nominal length l, the overall length (head included), as the standard measures it. """ from steve import Model size = "M4" # Thread size length = 12 # mm Nominal length (overall, head included) material = "steel" # Material # ISO 10642:2004, Table 1 (official preview p. 4: # https://cdn.standards.iteh.ai/samples/34454/32dec7e84d974361b85f744935ab2175/ISO-10642-2004.pdf; also # https://fasten.it/en/Norms/Norm/DIN%20EN%20ISO%2010642, editions 2004-06 and 2013-04). size: (thread d, head diameter dk theoretical max, head diameter dk actual min, # head height k max, hexagon socket s, socket depth t min) DIMENSIONS = { "M3": (3.0, 6.72, 5.54, 1.86, 2.0, 1.1), "M4": (4.0, 8.96, 7.53, 2.48, 2.5, 1.5), "M5": (5.0, 11.2, 9.43, 3.1, 3.0, 1.9), "M6": (6.0, 13.44, 11.34, 3.72, 4.0, 2.2), "M8": (8.0, 17.92, 15.24, 4.96, 5.0, 3.0), "M10": (10.0, 22.4, 19.22, 6.2, 6.0, 3.6), "M12": (12.0, 26.88, 23.12, 7.44, 8.0, 4.3), } # 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_th, dk, k, s, t = DIMENSIONS[size] material_id, colour = MATERIALS[material] total = max(length, k + 0.5) land = (dk_th - dk) / 2 # the 90° cone reaches dk this far under the top face model = Model() with model.sketch("profile", on="XZ", name="Profile") as sk: sk.polyline("outline", [(0, 0), (dk / 2, 0), (dk / 2, -land), (d / 2, -k), (d / 2, -total), (0, -total)]) model.revolve("body", "profile", axis="Z", name="Screw") with model.sketch("socket_sketch", on="XY", 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()