"""Metric threaded rod (DIN 976-1 form A) and double-ended stud, M2 to M36, any length. Envelope model for assemblies: a plain cylinder at the nominal thread diameter d (the thread is not modelled). One end is on the XY plane at the origin, the rod along +Z; `length` is the overall length. """ from steve import Model size = "M8" # Thread size length = 100 # mm Length (overall) material = "steel" # Material # DIN 976-1:2016-09 size table (https://fasten.it/en/Norms/Norm/DIN%20976-1): size -> nominal (major) diameter d, mm # (Md: d = M-number by the designation, ISO 261 coarse pitch series) DIAMETERS = { "M2": 2.0, "M2.5": 2.5, "M3": 3.0, "M4": 4.0, "M5": 5.0, "M6": 6.0, "M8": 8.0, "M10": 10.0, "M12": 12.0, "M14": 14.0, "M16": 16.0, "M20": 20.0, "M24": 24.0, "M30": 30.0, "M36": 36.0, } # material choice: (STEVE material library id, appearance colour) MATERIALS = { "steel": ("steel-generic", "#b4b8bd"), # property class 4.8 / 8.8, zinc plated "stainless-a2": ("stainless-304", "#c9ccd0"), # ISO 3506-1 A2-70 "stainless-a4": ("stainless-316", "#c9ccd0"), # ISO 3506-1 A4-70 "brass": ("brass", "#c8a44d"), } d = DIAMETERS[size] material_id, colour = MATERIALS[material] model = Model() with model.sketch("rod_sketch", on="XY", name="Section") as sk: sk.circle("rod_circle", (0, 0), d / 2) model.extrude("rod", "rod_sketch", distance=length, name="Rod") model.material(material_id, color=colour) result = model.result()