"""Parallel key, form A (both ends rounded), DIN 6885-1: width b, height h, overall length l. Centred on the origin: length along X, width along Y, base on the XY plane.""" from steve import Model size = "5x5" # Key width x height length = 20 # mm Key length # b x h: (width b, height h). DIN 6885-1:1968, table of key sizes, as listed at # https://fasten.it/en/norms/norm/din_6885-1 (shaft ranges there too). KEYS = {"2x2": (2, 2), "3x3": (3, 3), "4x4": (4, 4), "5x5": (5, 5), "6x6": (6, 6), "8x7": (8, 7), "10x8": (10, 8), "12x8": (12, 8)} b, h = KEYS[size] if length <= b: raise ValueError(f"A {size} key is longer than its {b} mm width.") model = Model() with model.sketch("outline", on="XY", name="Key") as sk: sk.slot("key", (-(length - b) / 2, 0), ((length - b) / 2, 0), b / 2) model.extrude("key", "outline", distance=h, name="Key") model.material("steel-generic", color="#a7abb0") result = model.result()