Threading: screw threads, rods & nuts

⚙️ Spec sheet →  —  visual schematic and metrics measured from a real rendered STL.

⚙️ Parts catalog →  —  this module is featured in the visual parts catalog.

Pure-Python port of the core of BOSL2’s threading.scad. The ThreadedRod and ThreadedNut classes build screw threads by generating the whole rod (core + helical thread) as one manifold polyhedron – an angular sweep of the thread profile stacked over every turn – so the result is always watertight. (Sweeping the thread and CSG-unioning a coaxial core instead is what Manifold cannot triangulate cleanly, so this port builds the polyhedron directly, as BOSL2 does.)

Convenience functions return pre-configured rods and nuts:

iso_threaded_rod(12, 24, 1.75)                       # ISO M12 x 1.75
acme_threaded_rod(20, 30, 4)                         # 29-degree ACME
iso_threaded_nut(18, 12, 10, 1.75, slop=0.1)        # matching hex nut

A rod is a threaded cylinder; a nut is a hex/square block with a matching threaded hole (cut by a thread “tap”, with slop radial clearance). pitch is the axial distance between threads, starts the number of thread starts, and left_handed flips the helix. The thread profiles are ported verbatim from BOSL2 (checked in tests/test_threading.py), and the geometry is verified watertight with the correct major/minor diameter and length.

Coverage of BOSL2 threading.scad

BOSL2 function

Status

Notes

generic_threaded_rod / generic_threaded_nut

ported

the profile-driven core every other builder uses.

threaded_rod / threaded_nut

ported

ISO (metric) / UTS 60-degree triangular threads.

trapezoidal_threaded_rod / trapezoidal_threaded_nut

ported

symmetric trapezoidal (metric trapezoidal by default; thread_angle / thread_depth).

acme_threaded_rod / acme_threaded_nut

ported

29-degree ACME threads.

square_threaded_rod / square_threaded_nut

ported

square-profile threads.

buttress_threaded_rod / buttress_threaded_nut

ported

asymmetric buttress threads.

thread_helix

ported

a single helical thread ridge, to add onto your own cylinder.

blunt-start / lead-in tapers, teardrop, bevels

not ported

the BOSL2 end-refinements; this port cuts the ends flush. A follow-up.

ball_screw_rod / npt_threaded_rod / bspp_threaded_rod

not ported

specialised thread forms; a follow-up.

Examples

An ISO M16 x 2 rod:

from pybosl2.parts.threading import iso_threaded_rod
iso_threaded_rod(16, 30, 2, fa=4, fs=1).show()
Loading 3-D preview…

⬇ Download STL mesh

An ACME lead screw:

from pybosl2.parts.threading import acme_threaded_rod
acme_threaded_rod(24, 36, 5, fa=4, fs=1).show()
Loading 3-D preview…

⬇ Download STL mesh

A rod threaded into its matching hex nut (shown side by side):

from pybosl2.parts.threading import iso_threaded_rod, iso_threaded_nut
rod = iso_threaded_rod(12, 30, 1.75, fa=6, fs=1).shape()
nut = iso_threaded_nut(18, 12, 10, 1.75, slop=0.1, fa=6, fs=1).shape().right(22)
(rod | nut).show()
Loading 3-D preview…

⬇ Download STL mesh

API reference

class pybosl2.parts.threading.ThreadedRod(d, l, pitch, profile, starts=1, left_handed=False, fn=None, fa=None, fs=None)[source]

Bases: object

A threaded rod built from an explicit 2-D thread profile.

profile is a ThreadProfile or a plain point list in pitch units (x in [-1/2, 1/2], y the depth fraction). starts is the number of thread starts and left_handed flips the helix.

Examples

An M20×2.5 ISO threaded rod, 30 mm long:

from pybosl2.parts.threading import ThreadedRod, iso_threaded_rod
iso_threaded_rod(d=20, l=30, pitch=2.5, fa=6, fs=1).show()
Loading 3-D preview…

⬇ Download STL mesh

Parameters:
d : float

l : float

pitch : float

profile : list[list[float]] | ThreadProfile

starts : int

left_handed : bool

fn : int | None

fa : float | None

fs : float | None

property diameter : float

Nominal outer diameter in mm.

property length : float

Length in mm.

property pitch : float

Thread pitch in mm.

property starts : int

Number of thread starts.

property left_handed : bool

True for left-handed threads.

shape()[source]

Build and return the threaded rod geometry (cached).

Return type:

CsgSolid

show()[source]

Display the threaded rod in the viewer.

Return type:

None

class pybosl2.parts.threading.ThreadedNut(nutwidth, id, h, pitch, profile, shape=NutShape.HEX, starts=1, left_handed=False, slop=0.0, fn=None, fa=None, fs=None)[source]

Bases: object

A nut: a hex or square body with a threaded hole cut by a matching thread tap.

Examples

An M8 nut for an M8×1.25 rod:

from pybosl2.parts.threading import ThreadedNut, iso_threaded_nut
iso_threaded_nut(nutwidth=13, id=8, h=6.8, pitch=1.25).show()
Loading 3-D preview…

⬇ Download STL mesh

Parameters:
nutwidth : float

id : float

h : float

pitch : float

profile : list[list[float]] | ThreadProfile

shape : NutShape

starts : int

left_handed : bool

slop : float

fn : int | None

fa : float | None

fs : float | None

property nutwidth : float

Across-flats width in mm.

property inner_diameter : float

Inner (threaded) diameter in mm.

property height : float

Nut thickness in mm.

property pitch : float

Thread pitch in mm.

property nut_shape : NutShape

Nut outer shape.

property starts : int

Number of thread starts.

property left_handed : bool

True for left-handed threads.

shape()[source]

Build and return the nut geometry (cached).

Return type:

CsgSolid

show()[source]

Display the nut in the viewer.

Return type:

None

class pybosl2.parts.threading.ThreadHelix(d, pitch, thread_depth=None, flank_angle=15, turns=1, starts=1, left_handed=False, profile=None)[source]

Bases: object

A single helical thread ridge, for adding threads onto your own cylinder.

The thread crest is at diameter d; give thread_depth and flank_angle, or an explicit profile. Built entirely through spiral_sweep (VNF output), so it does not accept fn/fa/fs smoothing parameters.

Examples

A trapezoidal thread helix around a cylinder:

from pybosl2.shapes3d import cylinder as cyl
from pybosl2.parts.threading import ThreadHelix
(cyl(diameter=20, height=30) | ThreadHelix(d=20, pitch=5, turns=6).shape()).show()
Loading 3-D preview…

⬇ Download STL mesh

Parameters:
d : float

pitch : float

thread_depth : float | None

flank_angle : float

turns : float

starts : int

left_handed : bool

profile : list[list[float]] | ThreadProfile | None

property diameter : float

Crest diameter in mm.

property pitch : float

Thread pitch in mm.

property turns : float

Number of turns.

property starts : int

Number of thread starts.

property left_handed : bool

True for left-handed threads.

shape()[source]

Return the helix geometry.

Return type:

CsgSolid

show()[source]

Display the helix in the viewer.

Return type:

None

Examples

These mirror the examples in BOSL2’s threading.scad, rendered live through PythonSCAD. Examples that rely on BOSL2’s attachment/anchor system, or on features not in this port, are omitted.

threaded_rod

An ISO/UTS threaded rod:

from pybosl2.parts.threading import iso_threaded_rod
iso_threaded_rod(d=25, l=20, pitch=2).show()
Loading 3-D preview…

⬇ Download STL mesh

Left-handed:

from pybosl2.parts.threading import iso_threaded_rod
iso_threaded_rod(d=10, l=20, pitch=1.25, left_handed=True).show()
Loading 3-D preview…

⬇ Download STL mesh

threaded_nut

A hex nut:

from pybosl2.parts.threading import iso_threaded_nut
iso_threaded_nut(nutwidth=16, id=8, h=8, pitch=1.25).show()
Loading 3-D preview…

⬇ Download STL mesh

trapezoidal_threaded_rod

A trapezoidal-thread rod:

from pybosl2.parts.threading import trapezoidal_threaded_rod
trapezoidal_threaded_rod(d=10, l=40, pitch=2).show()
Loading 3-D preview…

⬇ Download STL mesh

trapezoidal_threaded_nut

Its nut:

from pybosl2.parts.threading import trapezoidal_threaded_nut
trapezoidal_threaded_nut(nutwidth=16, id=8, h=8, pitch=2).show()
Loading 3-D preview…

⬇ Download STL mesh

acme_threaded_rod

An Acme lead screw:

from pybosl2.parts.threading import acme_threaded_rod
acme_threaded_rod(d=10, l=30, pitch=2, starts=3).show()
Loading 3-D preview…

⬇ Download STL mesh

acme_threaded_nut

An Acme nut:

from pybosl2.parts.threading import acme_threaded_nut
acme_threaded_nut(nutwidth=16, id=10, h=10, pitch=2).show()
Loading 3-D preview…

⬇ Download STL mesh

buttress_threaded_rod

A buttress-thread rod:

from pybosl2.parts.threading import buttress_threaded_rod
buttress_threaded_rod(d=10, l=20, pitch=1.25).show()
Loading 3-D preview…

⬇ Download STL mesh

buttress_threaded_nut

Its nut:

from pybosl2.parts.threading import buttress_threaded_nut
buttress_threaded_nut(nutwidth=16, id=8, h=8, pitch=1.25).show()
Loading 3-D preview…

⬇ Download STL mesh

square_threaded_rod

A square-thread rod:

from pybosl2.parts.threading import square_threaded_rod
square_threaded_rod(d=10, l=20, pitch=2, starts=2).show()
Loading 3-D preview…

⬇ Download STL mesh

square_threaded_nut

Its nut:

from pybosl2.parts.threading import square_threaded_nut
square_threaded_nut(nutwidth=16, id=10, h=10, pitch=2, starts=2).show()
Loading 3-D preview…

⬇ Download STL mesh

thread_helix

A single thread ridge, swept as a helix:

from pybosl2.parts.threading import ThreadHelix
ThreadHelix(d=10, pitch=2, thread_depth=0.75, flank_angle=15, turns=2.5).show()
Loading 3-D preview…

⬇ Download STL mesh