OpenSCAD ISO metric thread library / functions

by TrevM, published

OpenSCAD ISO metric thread library / functions by TrevM Jul 21, 2012


Liked By

View All

Give a Shout Out

If you print this Thing and display it in public proudly give attribution by printing and displaying this tag.

Print Thing Tag


Thing Statistics

30929Views 6470Downloads Found in 3D Printer Accessories


Allows creation of standard nuts and bolts or allow threads to be included in projects.
THIS IS OLD VERSION, please see http://www.thingiverse.com/thing:311031


top of file includes calls to make bolts: M10x16, M8x16, M6x12 nuts: M10, M8, M6. simply uncomment a line and build then print, or create your own sizes or include into your own project so you can have threads.
Photos should show black and white nuts and bolts in M6, M8 and M10 sizes, black versions are standard bought steel, white versions are ones I printed in white ABS.
I have a Reprap Metric Mendel Prusa with LM8UU bearings, fishbone wade extruder, own design hot-end, MKII hot bed. Only got it going yesterday, not yet calibrated awaiting micrometer from ebay.
This is my first design in OpenSCAD, maths in not my strong point, but I think these are as close to accurate ISO Metric as I can get.

Hot-end has 0.5mm extrusion hole, used 0.2mm layers, I had to go down to 5mm/s speed to get these printed, I have not yet tried smaller sizes.

OK, so that was a shock, knocked up the original file quickly for self-use, uploaded as an after thought, did not expect that much interest!
There have been some concerns with CGAL rendering times with bolts.
So, see new version IsoThread_20120823.scad.
I have moved positional calculations into variables to they are now calculated only one per thread part and I have now included quality tables.

CGAL Rendering times
DELL Vostro Desktop - Intel i5-2400 @ 3.10 GHz - 16GB RAM

Original 15/07/2012
Windows 7 Home Premium - OpenSCAD 2012.04.01 (git c869c6e):
M10 nut 7 secs
M8 nut 9 secs
M6 nut 4 secs
M10x16 5 mins 35 secs
M8x16 8 mins 43 secs
M6x12 7 mins 27 secs
Ubuntu 10.04 LTS - OpenSCAD 2012.02.28:
M10 nut 4 secs
M8 nut 4 secs
M6 nut 2 secs
M10x16 2 mins 52 secs
M8x16 4 mins 36 secs
M6x12 3 mins 45 secs

New 23/08/2012
Windows 7 Home Premium - OpenSCAD 2012.04.01 (git c869c6e):
M10 nut 9 secs
M8 nut 10 secs
M6 nut 3 secs
M10x16 2 mins 16 secs
M8x16 2 mins 7 secs
M6x12 1 mins 4 secs

I may re-visit again later, I have an idea that 'may' work that could make it faster.

More from 3D Printer Accessories

view more

All Apps

Upgrade this Thing with Thingiverse Apps

No results.

Hello is it possible to get this file in Step for solidworks please? thanks a lot

Solidworks is not free, no way I'm paying for it.
I prefer OpenSCAD because it is free and open source and I think it is wonderful.
But, because it is free and open source, it does not have some of the extras that come with paid for software, such as thread libraries, hence I created 1. I'm sure that if you look hard, you will find that Solidworks comes with threads 'out of the box', see here:

Same here I dont have solidworks program haha, its way too expensive for my pocket. I just needed the Stp file to loaded on my free Creo elements. I just need to modify the bolt for other things Thanks so much for the link.

All i get from all of cad files i download is ERROR: CSG generation failed! (no top level object found)

Yes, that is exactly correct, it is a library, it is not supposed to work on it's own.
If you open the file, near the top are examples of use.
//hex_bolt(10,16); // make an M10 x 16 ISO bolt
remove the comment lines from the start like:
hex_bolt(10,16); // make an M10 x 16 ISO bolt
Now you will have a top level object that will give you an M10 x 16 bolt

I am looking for a way to create a cylinder (internal diameter 54mm, wall thickness 1mm - so it will need to be a fine thread) with a thread on the inside (this is for several parts of a model rocket). This is by far the easiest scad thread library to understand (I am an scad neophyte), but I am having difficulty in seeing how to do this by modifying your library. Any hints would be most appreciated!

Hi Crispin,
Duh, I'm going nuts....
To put a thread on the inside (as you actually said), use this line instead:
translate([0,0,45]) thread_in_pitch(54,5,0.5);
The translate moves up to 5 mm before top of cylinder.
It creates a thread of 54 mm (inside diameter) that is 5 mm long (high) with pitch of 0.5.

Hi Crispin,
Please don't use this old version, click on Remixes and go to the updated version. This version was the very first thing I created in OpenSCAD, updated version is much cleaner and easier:
You need to put my file either in the library directory or same directory as your file.
Then, to use the library, put this line at the top of your file:
use <isothread.scad>
To create a cylinder with sizes you gave, you will need something like:
translate([0,0,-0.1]) cylinder(r=54/2,h=50.2);
This creates a cylinder with diameter 56 mm then subtracts a cylinder of diameter 54 from it.
Then you need to add the thread like this:
translate([0,0,45]) thread_out_pitch(56.5,5,0.5);
The translate moves up to 5 mm before top of cylinder.
It creates a thread of 56.5 mm (56 mm inside diameter + 0.5 inch thread size) that is 5 mm long (high) with pitch of 0.5.
I think you may find printing to be a challenge.
Cylinder wall thickness of 1 mm will be hard.
Thread of pitch 0.5 will be very hard.
You may need to re-think.
You could also see my other thing Big Tube:
I think this may be close to what you need as a starting point.

OpenSCAD ISO metric thread library / functions (updated)
by TrevM
Big tube
by TrevM

It worked like a char - many thanks for your help.
Do you know if there is a way to have OpenSCAD calculate the volume of an object it constructs?

Hi Crispin,
Nothing automatic, it has full maths capability though, so you could do it with each part and add them up into a variable then use echo command to display result.

Many thanks for this - I've downloaded the update and will try your suggestions. I can see the problem with threading a 1mm wall thickness. I'll need to create an insert for the body tube and thread that so that I can screw in the entire rear section (the motor and fin assembly) which is what I am 3D printing. This is the first part of what will eventually be a glide-back rocket project I am building with the kids at my school.

I need to use this to make a nut and bolt that are thread size 13 with the nut's internal diameter 19mm (to fit shower head). What do I input for this?

Um, your problem does not compute!
will give you a standard ISO 13 mm thread
will give you a standard ISO 13 mm bolt that is 20 mm long
All threads have a coarseness index, that is how deep the grooves are, which also relates to pitch (length between 1 ridge and the next).
Most ISO threads are either fine or coarse, at 13 mm you are usually saying thread is 0.75 mm or 1 mm respectively.
But normally the threaded part of a 13 mm bolt has outside diameter of 13 mm + coarse (13.75 or 14 mm) and inside diameter of a 13 mm nut is 13 mm - coarse (12.25 mm or 12 mm ).
So 13 mm thread with an inside diameter of 19 mm is not possible.

Ok, my fault, I suppose that I should restate the issue. Using a thread gauge that I have with my tap and die set, I was able to determine that the thread size is 13 (13 threads/inch). I need to make a nut that is 13 threads/inch with the nut having internal diameter of 19 mm so that it will fit onto the shower head.

Sorry for the confusion.


Is what I think you need.
With metric threads you basically need thread metric diameter and pitch (distance between threads).
You have diameter, you measured that as 19 mm.
Problem is pitch, you measured 13 threads per inch, = 13 threads in 25.4 mm = pitch of 1.95 mm.

Look in my .scad file, you will see:
// function for thread pitch
function get_coarse_pitch(dia) = lookup(dia, [

See in the middle: [18,2.5],[20,2.5]

ISO threads do not normally support 19 mm and standard pitch would be 2.5 mm.
But, just add [19,1.95] and it should work.

One way I found to speed this library up is to generate shorter lengths (just a couple of turns of the threads), then duplicate this shape and translate and rotate it a bit so it forms the next part of the thread. Keep doing this a few times and you end up with a longer thread which renders quite quickly. Each generated section is cached then reused, so it is much quicker. One quick calculation I did showed that a render I was attempting would have taken 3 years (as the time goes up geometrically). However, I got it down to a few minutes.

Nice one, thanks for sharing, will try that myself :-)

Just try and i got a problem for rendering bold (nuts are fine)... bold compile but do not render (rendering seems to enter an infinite loop), so i can't make a STL.

Using OpenSCAD 2012.7.14 for MacOS.

This sounds like complexity problem, threads on nuts are quite short, threads on bolts are usually longer. The threads are made out of lots of polygons, trianguar on ends, rectangular on sides. Either wait and it will render, or look for line in ISOThread.scad:

module thread_out(dia,hi,thr=32)

3rd parameter is complexity, 32 means 32 polygons for each turn of thread, reduce this to 15 and try again, you should see the effect on a normal compile.

I have printed the M8 hex nut. The thread work perfect! but the diameter and height are wrong. I have changed them according to :


and now the nuts are exactly as the metal ones :-) I have only tested the M8. The diameter and height I have changed in the openscad are:

  • Diam: [8,14.60]
  • Hi: [8,4.5]

Now they work perfectly wel with the hex key (#13)

Thank you very m
uch for your work! :-)

I know, standards are nice, but so many of them :-(

Threads were ok, Wikipedia shows the maths of ISO threads, but even there, the standards are not clear, coarse and fine, some sizes missing so added by France etc. I just put in all the coarse sizes.

Then I came to hex head sizes and I did actually find the fairbury fastener link and used it to create all the tables. Then I wanted to test, my son had a set of Rolson nuts and bolts M4 to M10 :-) The sizes of the Rolson nuts and bolts are different! So I modified the tables to reflect the Rolson sizes.

The photos show they now match, the black nuts and bolts are Rolson steel, the white are my printed white ABS versions.

But I specifically put all the important sizes in tables so they can be easily modified.

Have Fun :-)

It is amazing!!!! Thank you very much for sharing! :-)

I have just tested the M8 hex nut and it works great!!! Now we can use these nuts for the Prusa :-)

I have taken a video showing how well 2 Hex nuts are screwed on a threaded rod