Sign in with STEVE

steve/nut-trap

Hex nut trap: a hexagonal prism to cut a pocket for a metric hexagon nut, M1.6 to M12, DIN 934 or ISO 4032 nut sizes.

v1.0.0 Latest STEVE MIT 6
Isometric
part.py 42 lines · Python · STEVE runtime · checked
Download
1"""Hex nut trap: a hexagonal prism to cut a pocket for a metric hexagon nut with, DIN 934 or ISO 4032 nut sizes.
2Axis along Z, the top face on the XY plane, the prism running down for the depth; two corners of the hexagon lie on the X
3axis. Dimensions in the README."""
4import math
5
6from steve import Model
7
8thread = "M3" # Thread
9nut = "DIN 934" # Nut standard: DIN 934 or ISO 4032
10clearance = 0 # mm Gap added on each flat (0: the nut's own largest width across flats)
11depth = 0 # mm Depth (0: the nut's largest height m)
12
13# thread: (s nom = max, m nom = max) in mm, the nut's width across flats and height.
14# DIN 934: Westfield Fasteners product specification "DIN 934 - Full Hex Nuts (Standard Pitch)", Table 1, Dimensions &
15# Tolerances according to DIN 934 (PDF dated 2026-01-02, page 1, https://westfieldfasteners.co.uk/Standards/Nut-Hex-M.pdf).
16# ISO 4032: the table "according to EN ISO 4032" at https://www.fasteners.eu/standards/DIN/934/ (rows m max. and s nominal =
17# max.; read 2026-11-14), the same values as the metric-nut part's ISO 4032 table.
18NUTS = {
19 "DIN 934": {"M1.6": (3.2, 1.3), "M2": (4, 1.6), "M2.5": (5, 2), "M3": (5.5, 2.4), "M3.5": (6, 2.8), "M4": (7, 3.2), "M5": (8, 4), "M6": (10, 5),
20 "M8": (13, 6.5), "M10": (17, 8), "M12": (19, 10)},
21 "ISO 4032": {"M1.6": (3.2, 1.3), "M2": (4, 1.6), "M2.5": (5, 2), "M3": (5.5, 2.4), "M3.5": (6, 2.8), "M4": (7, 3.2), "M5": (8, 4.7), "M6": (10, 5.2),
22 "M8": (13, 6.8), "M10": (16, 8.4), "M12": (18, 10.8)},
23}
24
25if nut not in NUTS:
26 raise ValueError(f"no nut standard {nut!r}: {', '.join(NUTS)}")
27if thread not in NUTS[nut]:
28 raise ValueError(f"no {nut} nut {thread!r} here: {', '.join(NUTS[nut])}")
29if clearance < 0 or depth < 0:
30 raise ValueError("clearance and depth can't be negative")
31s, m = NUTS[nut][thread]
32flats = s + 2 * clearance
33deep = depth if depth > 0 else m
34corner = flats / math.sqrt(3) # centre to corner of a hexagon with this width across flats
35outline = [(corner * math.cos(math.radians(60 * i)), corner * math.sin(math.radians(60 * i))) for i in range(6)]
36
37model = Model()
38with model.sketch("trap_sketch", on="XY", name="Nut trap") as sk:
39 sk.polyline("trap_outline", outline, closed=True)
40model.extrude("trap", "trap_sketch", distance=-deep, name="Nut trap")
41result = model.result()
42

A hexagonal prism to cut a nut pocket with: the nut's largest width across flats and height from DIN 934 or ISO 4032, with a gap of your choice on each flat and a depth of your choice. See the README.

Nut trap

A hexagonal prism to cut a pocket for a metric hexagon nut with. Its axis is along Z, its top face is on the XY plane, and it runs down for the depth. Two corners of the hexagon lie on the X axis.

Source

Thread DIN 934 s DIN 934 m ISO 4032 s ISO 4032 m
M1.6 3.2 1.3 3.2 1.3
M2 4 1.6 4 1.6
M2.5 5 2 5 2
M3 5.5 2.4 5.5 2.4
M3.5 6 2.8 6 2.8
M4 7 3.2 7 3.2
M5 8 4 8 4.7
M6 10 5 10 5.2
M8 13 6.5 13 6.8
M10 17 8 16 8.4
M12 19 10 18 10.8

The pocket's width across flats is s plus twice the gap; its corners follow from that (width across flats divided by the square root of 3, from the centre). Its depth is m unless you set one.

The gap and the depth are yours to set; neither standard gives a pocket size. With a gap of 0 the pocket is exactly the largest nut the standard allows, so a real nut (always at or under s) fits with whatever its own tolerance leaves.

Not modelled

The bolt hole through the pocket's floor (use the clearance-hole part), and any slot to slide the nut in from the side.

Catalogue models

The old catalogue's negative_hex_nut_trap_M<n>_nominal entries (M2 to M8) give a width across flats and a height that are DIN 934's s and m for every size (M5 4, M6 5 and M8 6.5 high, where ISO 4032 has 4.7, 5.2 and 6.8). They map to the DIN 934 presets with no gap. They have no model to measure.

Its print_clearance_0p15mm and print_clearance_0p25mm entries name a clearance but not where it applies (on each flat or over the width across flats), give the same width as the nominal entries, and have no model to measure, so they are left out. Set the gap yourself. Its square nut, slot-in and side-insert pocket entries name only a thread and are left out for the same reason: no pocket size, slot length or clearance is given.

  1. 1.0.0 Latest
More #nut-trap
STEVEMIT

steve/metric-nut

Metric nuts: hex ISO 4032, thin ISO 4035, nylon-insert DIN 985, all-metal DIN 980, flange DIN 6923, cap DIN 1587, square DIN 557.

23 41 sizes 0 4 weeks ago v1.3.1
STEVEMIT

steve/hex-nut

Hex nut, ISO 4032, M2 to M12.

21 9 variants 0 1 month ago v1.1.0
STEVEMIT

steve/clearance-hole

Clearance hole cylinder for metric bolts and screws, M1.6 to M100: ISO 273 fine, medium and coarse, at the low, middle or high end of H12, H13 or H14.

9 216 sizes 0 3 weeks ago v1.0.1
STEVEMIT

steve/countersink-hole

Countersink for metric countersunk head screws, M1.6 to M10: ISO 15065's 90 degree countersink over its ISO 273 medium clearance hole, as a solid to cut with.

6 10 sizes 0 3 weeks ago v1.0.0