Thread milling G-code generator

Writes an example program for a single-profile thread mill: a tangential entry, one helical turn per pitch, and a tangential exit. Internal and external, right or left hand.

Example code – check it and dry-run it, at your own risk. This program is a generic example, not written for your machine or control. Read every line against your control’s manual, simulate it, then run it above the work in single block with reduced rapids and feed before cutting. Check the work offset, tool length offset, units and clearance heights. See the terms of use.
How it works, guides and notes

How it works

For an internal thread the tool centre runs on a radius of (major diameter − cutter)/2. For an external thread it is (minor diameter + cutter)/2, using the basic minor d − 1.226869P. Each full turn moves Z by exactly one pitch. A right-hand thread rises anticlockwise, so internal threads climb from the bottom with G3 and external threads work down from the top with G2 (both climb milling with M3). Left-hand threads reverse the Z direction.

The feed you enter is at the cutting edge. On an internal thread the tool centre travels a smaller circle, so the programmed feed is scaled by (D − cutter)/D. On an external thread it is scaled by (D + cutter)/D.

Hand check: M10 × 1.5 internal with a 6 mm cutter: centre radius (10 − 6)/2 = 2.000. 12 mm length = 8 turns. Z goes −12.0, −10.5 … 0.0, a change of 1.5 per turn. Edge feed 300 → centre feed 300 × 4/10 = 120 mm/min.

Basic-profile sizes have no tolerance. Measure the first part with a gauge and adjust the diameter the cutter must reach (or your wear offset). See the thread calculator for sizes.

FANUC, Haas, Siemens, Heidenhain, LinuxCNC and Grbl are names or trademarks of their respective owners. They are mentioned only to describe which controls a code format relates to. Lathe Calculator is not affiliated with or endorsed by any of them. Trademarks.

Spotted a mistake? Report an error.