Screws: metric screws, nuts & screw holes¶
Pure-Python port of the core of BOSL2’s screws.scad, built on top of the
Threading thread generator. The Screws class turns a
metric screw name into ready-to-print geometry:
Screws.screw("M6", 20, head="socket", drive="hex") # M6 x 20 socket cap screw, hex recess
Screws.nut("M6") # matching M6 hex nut
Screws.screw_hole("M6", 20, head="flat") # countersunk clearance hole to subtract
A screw is specified by name – "M6" (coarse pitch looked up from the ISO table), "M8x1" (an
explicit fine pitch), a bare number, or a {"diameter": ..., "pitch": ...} dict. Screws are built
head-up: the shaft occupies z in [-length, 0] (tip at the bottom) and the head sits above
z = 0, so a screw drops straight into a mating screw_hole() cut with
its mouth at z = 0.
The dimension tables (ISO coarse/fine pitches, and the socket-cap, hex, button, pan, countersunk,
setscrew and nut head sizes) are transcribed verbatim from screws.scad and checked in
tests/test_screws.py; the assembled geometry is verified watertight with the right head, shaft
and thread in tests/test_stl_render.py.
Coverage of BOSL2 screws.scad¶
BOSL2 feature |
Status |
Notes |
|---|---|---|
|
ported |
metric ISO sizes; returns a plain dict of resolved dimensions. |
|
ported |
threaded/plain/partly-threaded shaft, plus socket / hex / button / pan / flat / setscrew heads. |
|
ported |
hex or square nut with a matching threaded hole; |
|
ported |
clearance hole (close/normal/loose fit), flat-head countersink, counterbore, or tapped hole. |
hex / slot drive recess |
ported |
the two most common recesses; cut into the head (or the shaft top for a setscrew). |
phillips / torx drive recesses |
ported separately |
available as masks in Screw drives: Phillips, hex, Torx & Robertson recesses ( |
UTS / imperial specs, shoulder screws, named anchors, per-tolerance thread classes |
not ported |
a follow-up; this port covers the metric fastener geometry the toolkit needs. |
Examples¶
An M8 socket cap screw with a hex drive recess:
Screws.screw("M8", 24, head="socket", drive="hex", _fa=6, _fs=1).show()
A countersunk (flat-head) screw:
Screws.screw("M6", 20, head="flat", _fa=6, _fs=1).show()
A screw threaded into its matching hex nut (shown side by side):
screw = Screws.screw("M6", 18, head="button", drive="hex", _fa=6, _fs=1)
nut = Screws.nut("M6", slop=0.1, _fa=6, _fs=1).right(18)
(screw | nut).show()
API reference¶
- class bosl2.screws.Screws[source]¶
Bases:
objectMetric screws, nuts and screw holes (BOSL2 screws.scad), built on
Threading.Every method is a class method returning a
Bosl2Solid, exceptscrew_info(), which returns a plaindictof resolved dimensions. Screws are built head-up: the shaft occupiesz in [-length, 0](tip at the bottom) and the head sits abovez = 0.- static screw_info(spec, head='socket', thread='coarse', drive='none', pitch=None)[source]¶
Resolve a screw specification to a dict of dimensions.
Keys:
system,diameter,pitch,head,head_size,head_height,head_angle(flat heads only),drive,drive_size,drive_depth.- Parameters:
head (str)
thread (str)
drive (str)
pitch (float | None)
- static screw(spec, length, head='socket', drive='none', thread='coarse', thread_len=None, pitch=None, fn=None, fa=None, fs=None)[source]¶
A metric screw: a threaded (or plain) shaft plus a head, with an optional drive recess.
length is the shaft length below the head (for a flat head, below the surface). Set
thread="none"for a plain unthreaded shank, orthread_lenfor a partly-threaded shaft.- Parameters:
length (float)
head (str)
drive (str)
thread (str)
thread_len (float | None)
pitch (float | None)
fn (int | None)
fa (float | None)
fs (float | None)
- Return type:
- static nut(spec, thickness='normal', shape='hex', thread='coarse', nutwidth=None, slop=0.0, pitch=None, fn=None, fa=None, fs=None)[source]¶
A hex or square nut with a threaded hole matching spec (BOSL2 nut()).
thickness is
"normal","thin","thick"or a number (mm). nutwidth overrides the standard across-flats width. slop adds radial clearance to the threaded hole.- Parameters:
thickness (float | str)
thread (str)
nutwidth (float | None)
slop (float)
pitch (float | None)
fn (int | None)
fa (float | None)
fs (float | None)
- Return type:
- static screw_hole(spec, length, head='none', counterbore=0.0, fit='normal', thread='none', pitch=None, fn=None, fa=None, fs=None)[source]¶
A hole cutter for a screw: clearance shaft, plus optional countersink (flat head) or counterbore.
Returns a solid to subtract from your part. The clearance shaft occupies
z in [-length, 0]with its mouth atz = 0; countersinks/counterbores open upward from there. Setthread="coarse"for a tapped (threaded) hole instead of a clearance hole.- Parameters:
length (float)
head (str)
fit (str)
thread (str)
pitch (float | None)
fn (int | None)
fa (float | None)
fs (float | None)
- Return type:
Examples¶
These mirror the examples in BOSL2’s screws.scad, rendered live through PythonSCAD.
Examples that rely on BOSL2’s attachment/anchor system, or on features not in this port, are omitted.
screw
An M6 screw:
Screws.screw("M6", length=12).show()
A socket-head M6:
Screws.screw("M6", head="socket", length=12).show()
A Torx button-head M6:
Screws.screw("M6", head="button", drive="torx", length=12).show()
nut
An M6 nut:
Screws.nut("M6").show()
screw_hole
A threaded screw-hole mask:
Screws.screw_hole("M6", length=10).show()