"""Hexagon socket set screw with flat point, ISO 4026 (DIN 913), M3 to M12, length l >= d. Envelope model for assemblies: plain cylinder at the nominal thread diameter d (the thread is not modelled), hexagon socket (key size s, depth t min for the length) at one end and a flat point of diameter dp max at the other, chamfered at 45°. The socket end is on the XY plane at the origin, the screw along -Z; `length` is the nominal (overall) length l. """ from steve import Model size = "M5" # Thread size length = 8 # mm Nominal length (overall) material = "steel" # Material # ISO 4026:2003, Table 1 (official preview p. 3: # https://cdn.standards.iteh.ai/samples/36431/f53ced64ab1946679bd80f0a0e6cac63/ISO-4026-2003.pdf; also # https://fasten.it/en/Norms/Norm/DIN%20EN%20ISO%204026, DIN EN ISO 4026:2004-05). # size: (thread d, flat point diameter dp max, hexagon socket s nominal, socket depth t min for the shortest length # (footnote d: lengths in the shaded cells, which are l = d for M3 to M12), t min for longer lengths (footnote e)) DIMENSIONS = { "M3": (3.0, 2.0, 1.5, 1.2, 2.0), "M4": (4.0, 2.5, 2.0, 1.5, 2.5), "M5": (5.0, 3.5, 2.5, 2.0, 3.0), "M6": (6.0, 4.0, 3.0, 2.0, 3.5), "M8": (8.0, 5.5, 4.0, 3.0, 5.0), "M10": (10.0, 7.0, 5.0, 4.0, 6.0), "M12": (12.0, 8.5, 6.0, 4.8, 8.0), } # material choice: (STEVE material library id, appearance colour) MATERIALS = { "steel": ("steel-generic", "#2b2d30"), # property class 45H, black oxide finish "stainless-a2": ("stainless-304", "#c9ccd0"), # ISO 3506-3 A2-21H "stainless-a4": ("stainless-316", "#c9ccd0"), # ISO 3506-3 A4-21H } d, dp, s, t_short, t_long = DIMENSIONS[size] if length < d: raise ValueError(f"ISO 4026 has no {size} screw shorter than {d:g} mm (its socket depth isn't defined there)") t = t_short if length <= d else t_long # the shaded (shortest) length is l = d for every size here material_id, colour = MATERIALS[material] point = (d - dp) / 2 # 45° chamfer from d down to the flat point dp model = Model() with model.sketch("profile", on="XZ", name="Profile") as sk: sk.polyline("outline", [(0, 0), (d / 2, 0), (d / 2, -(length - point)), (dp / 2, -length), (0, -length)]) 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()