"""Flat (countersunk) head socket cap screw, inch series, ASME B18.3, #0 to 1/2 in, UNC and UNF, any length. Envelope model for assemblies: 82 degree countersunk head of diameter A (theoretical sharp, max), hexagon socket (nominal key size J, depth T = key engagement min) and a plain shank at the basic major diameter D of ASME B1.1 (the thread is not modelled). The head's top face is on the XY plane at the origin and the screw points along -Z; `length` (inches) is the nominal length L, overall (head included), as for all flat head screws. The model is in millimetres (1 in = 25.4 mm). """ import math from steve import Model size = "#10-24" # Thread (Unified, ASME B1.1) length = 0.5 # in Nominal length, overall material = "steel" # Material # Thread designation: nominal size THREADS = { "#0-80": "#0", "#1-64": "#1", "#1-72": "#1", "#2-56": "#2", "#2-64": "#2", "#3-48": "#3", "#3-56": "#3", "#4-40": "#4", "#4-48": "#4", "#5-40": "#5", "#5-44": "#5", "#6-32": "#6", "#6-40": "#6", "#8-32": "#8", "#8-36": "#8", "#10-24": "#10", "#10-32": "#10", "1/4-20": "1/4", "1/4-28": "1/4", "5/16-18": "5/16", "5/16-24": "5/16", "3/8-16": "3/8", "3/8-24": "3/8", "7/16-14": "7/16", "7/16-20": "7/16", "1/2-13": "1/2", "1/2-20": "1/2", } # Sources (README): D from NBS Handbook H28 (1969) Table 2.7; the rest ASME B18.3-2012 Table 8 # (https://www.globalfastener.com/standards/detail_20306.html), same values in B18.3-2003. # Inches. ASME B1.1 basic major diameter D; ASME B18.3 Table (flat countersunk head socket cap screws): head # diameter A (theoretical sharp, max), hexagon socket size J (nominal key), key engagement T min. The head height # follows from the 82 degree head angle: (A - D) / 2 / tan(41 deg) (the table's reference value H). # nominal: (D, A, J, T) DIMENSIONS = { "#0": (0.0600, 0.138, 0.035, 0.025), "#1": (0.0730, 0.168, 0.050, 0.031), "#2": (0.0860, 0.197, 0.050, 0.038), "#3": (0.0990, 0.226, 0.0625, 0.044), "#4": (0.1120, 0.255, 0.0625, 0.055), "#5": (0.1250, 0.281, 0.078125, 0.061), "#6": (0.1380, 0.307, 0.078125, 0.066), "#8": (0.1640, 0.359, 0.09375, 0.076), "#10": (0.1900, 0.411, 0.125, 0.087), "1/4": (0.2500, 0.531, 0.15625, 0.111), "5/16": (0.3125, 0.656, 0.1875, 0.135), "3/8": (0.3750, 0.781, 0.21875, 0.159), "7/16": (0.4375, 0.844, 0.25, 0.159), "1/2": (0.5000, 0.938, 0.3125, 0.172), } # material choice: (STEVE material library id, appearance colour) MATERIALS = { "steel": ("steel-generic", "#2b2d30"), # alloy steel, black oxide "stainless-18-8": ("stainless-304", "#c9ccd0"), "stainless-316": ("stainless-316", "#c9ccd0"), } INCH = 25.4 HEAD_ANGLE = 82 # degrees, included angle of the countersunk head D, A, J, T = DIMENSIONS[THREADS[size]] d = D * INCH dk = A * INCH s = J * INCH t = T * INCH overall = length * INCH cone = (dk - d) / 2 / math.tan(math.radians(HEAD_ANGLE / 2)) material_id, colour = MATERIALS[material] model = Model() with model.sketch("profile", on="XZ", name="Profile") as sk: sk.polyline("outline", [(0, 0), (dk / 2, 0), (d / 2, -cone), (d / 2, -overall), (0, -overall)]) 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()