"""Nut, inch series, Unified threads #0-80 to 1/2-20, ASME B18.2.2: hex and square nuts (machine screw nuts for #0 to #10, hex and square nuts for 1/4 to 1/2 in) and hex jam nuts (1/4 to 1/2 in). Envelope model for assemblies: a hexagonal or square prism (width across flats F, thickness H; corner chamfers not modelled) with a plain bore at the basic major diameter D of ASME B1.1 (the thread is not modelled). It sits on the XY plane, centred on the origin, axis along +Z. The model is in millimetres (1 in = 25.4 mm). """ from steve import Model size = "1/4-20" # Thread (Unified, ASME B1.1) style = "hex" # Nut style 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", } # Inches. ASME B1.1-1989 (R2001) basic major diameter D, https://www.engineersedge.com/screw_threads_chart.htm DIAMETERS = { "#0": 0.0600, "#1": 0.0730, "#2": 0.0860, "#3": 0.0990, "#4": 0.1120, "#5": 0.1250, "#6": 0.1380, "#8": 0.1640, "#10": 0.1900, "1/4": 0.2500, "5/16": 0.3125, "3/8": 0.3750, "7/16": 0.4375, "1/2": 0.5000, } # Inches, style: {nominal: (width across flats F, thickness H)}. # #0 to #10: ASME B18.2.2 square and hex machine screw nuts (Table 1-1 of the 2010 edition, Table 1.1.1-1 of 2022): # F basic and H max (the table gives thickness as min / max only), https://www.fasten.it/Norms/Norm/ASME_B18.2.2_TABLE_1-1 # (2010), also https://www.engineersedge.com/hardware/hexagon_machine_screw_nuts_14062.htm (F basic as fractions). # 1/4 to 1/2: ASME B18.2.2 hex nuts, hex jam nuts and square nuts, F basic and H basic, # https://www.engineersedge.com/hex_nut.htm, https://amesweb.info/Fasteners/Nut/Hex-Nut-Sizes-Dimensions-Table.aspx, # https://www.aftfasteners.com/hex-jam-nuts-dimensions-technical-information/, # https://amesweb.info/Fasteners/Nut/Square-Nuts-Dimensions.aspx (B18.2.2-2010 via Machinery's Handbook 30th ed.). NUTS = { "hex": { "#0": (0.15625, 0.050), "#1": (0.15625, 0.050), "#2": (0.1875, 0.066), "#3": (0.1875, 0.066), "#4": (0.25, 0.098), "#5": (0.3125, 0.114), "#6": (0.3125, 0.114), "#8": (0.34375, 0.130), "#10": (0.375, 0.130), "1/4": (0.4375, 0.21875), "5/16": (0.5, 0.265625), "3/8": (0.5625, 0.328125), "7/16": (0.6875, 0.375), "1/2": (0.75, 0.4375), }, "jam": { "1/4": (0.4375, 0.15625), "5/16": (0.5, 0.1875), "3/8": (0.5625, 0.21875), "7/16": (0.6875, 0.25), "1/2": (0.75, 0.3125), }, "square": { "#0": (0.15625, 0.050), "#1": (0.15625, 0.050), "#2": (0.1875, 0.066), "#3": (0.1875, 0.066), "#4": (0.25, 0.098), "#5": (0.3125, 0.114), "#6": (0.3125, 0.114), "#8": (0.34375, 0.130), "#10": (0.375, 0.130), "1/4": (0.4375, 0.21875), "5/16": (0.5625, 0.265625), "3/8": (0.625, 0.328125), "7/16": (0.75, 0.375), "1/2": (0.8125, 0.4375), }, } # material choice: (STEVE material library id, appearance colour) MATERIALS = { "steel": ("steel-generic", "#b8bcc2"), # carbon steel, zinc plated "stainless-18-8": ("stainless-304", "#c9ccd0"), "stainless-316": ("stainless-316", "#c9ccd0"), } # style: (polygon sides, rotation in degrees): hexagon corners on X, square sides parallel to X and Y SHAPES = {"hex": (6, 0), "jam": (6, 0), "square": (4, 45)} INCH = 25.4 nominal = THREADS[size] F, H = NUTS[style][nominal] d = DIAMETERS[nominal] * INCH s = F * INCH m = H * INCH sides, turn = SHAPES[style] material_id, colour = MATERIALS[material] model = Model() with model.sketch("nut_sketch", on="XY", name="Nut") as sk: sk.polygon("outline", (0, 0), s / 2, sides, inscribed=False, rotation=turn) sk.circle("bore", (0, 0), d / 2) model.extrude("nut", "nut_sketch", distance=m, name="Nut") model.material(material_id, color=colour) result = model.result()