Poor man's openscad screw library

by aubenc, published

Poor man's openscad screw library by aubenc May 25, 2011

Featured Thing!

17 Share
Download All Files

Thing Apps Enabled

Order This Printed View All Apps



Public Domain
Poor man's openscad screw library by aubenc is licensed under the Public Domain license.

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

137936Views 44231Downloads Found in Engineering


Due to some bugs in the initial version, a revision of the OpenSCAD library has been uploaded, please use "polyScrewThread_r1.scad". Thanks a lot to mechadense for reporting the bugs!

This is my humble take on a screw library to be used in your OpenSCAD scripts.

If you are serious, please be, you'll better use http://www.thingiverse.com/thing:8793 syvwlch.

Anyway, I had this thing for months in the lost projects folder suffering from some serious issues, well some of them remain (it doesn't render) and once the dust has been shaken it compiles quite nice and printable things.

Instead of functions, this thing uses loops.
Instead of rotate polyhedrons, this thing draws the polyhedron in a new set of points.

Just a couple of comments to help using this thing:

  • I've found that a resolution of something like 1.5mm (PI/2 is what I use the most) works very well for threads that will be used with nuts made with a resolution of 0.5mm.

  • I've printed the threads with a very low infill (0.2) but for the nuts, setting up this value (I've used 0.45) helped a lot with the overhang issue.

More pics @ http://aubenc.imgur.com/screws_threads_an_other_polyhedron_games


Do not use "polyScrewThread.scad", in contains some bugs! Instead...

Drop "polyScrewThread_r1.scad" into your OpenSCAD library folder or the folder where you are writing your OpenSCAD script.

Use polytests.scad (*) as a user's guide, refference, whatever.

(* - Depending on how old/new is your OpenSCAD you may need to change the line where the library is included, replace "include" by "use")

Because this thing is made without much science, you'll need to tweak a little bit, sorry...

First print a nut (high res, see comments above), tweak the infill and/or the degrees for the shape of the thread.

Once your nut prints fine, print a short threaded rod, try to change the resolution of the thread, infill,... use your imagination.

I printed the provided examples and they all work fine without any cleaning, that's the reason why they look so ugly in the pictures.

Design bolted things.

Print bolted things.

Bolt things.

Keep on bolting!

More from Engineering

view more

All Apps

Auto-magically prepare your 3D models for 3D printing. A cloud based 3D models Preparing and Healing solution for 3D Printing, MakePrintable provides features for model repairing, wall thickness...

App Info Launch App

Kiri:Moto is an integrated cloud-based slicer and tool-path generator for 3D Printing, CAM / CNC and Laser cutting. *** 3D printing mode provides model slicing and GCode output using built-in...

App Info Launch App
KiriMoto Thing App

With 3D Slash, you can edit 3d models like a stonecutter. A unique interface: as fun as a building game! The perfect tool for non-designers and children to create in 3D.

App Info Launch App

Print through a distributed network of 3D printing enthusiasts from across the US, at a fraction of the cost of the competitors. We want to change the world for the better through technology, an...

App Info Launch App

Treatstock is an online platform that offers decentralized manufacturing services such as 3D printing and CNC machining for clients all over the world. We offer free and instant access to comparati...

App Info Launch App

3D print your favourite design with NinjaPrototype, a professional 3D manufacture with consistent quality and speed.

App Info Launch App

Hi, I tried to create a M8 bolt and nut
I figured that the toothshape needs to be 30° for metric standard,
The Bolt with hex_screw(8,1.25,30,40,1.5,2,13,6,0,0); interfaced nicely with a metal nut wight away
for the nut I had to change the diameter do 8.7 in order to get a good fit. hex_nut(13,6,1.25,30,8.7,0.5);
anybody else facing this issue?
As I understood the exampled it was supposed to match with a 8 diameter for the nut right?

good work anyhow, thanks

Hi, this thing "as is" is not intended to create ISO thread profiles.
You were lucky that something seemed to work but it was just luck :)

Short tale: You should...
1.- Create a thread with a outer diameter bigger than your desired size.
2.- (this one could be skipeed) Use OpenSCAD's union() function to add a cylinder to smooth the inner edges of the thread.
3.- Use then an intersection() (or a difference() could also work) to trim out the outer edges.

Don't hesitate to make a internet search on "metric thread iso profile" or something like to find out the dimensions required for the steps above.

If you scroll down in the comments you will find other thingiverse things that where made for ISO profiles.
There is also (I may be wrong here) some comments discussing the way to use this to create metric or "imperial" threads.

Good luck!

I'm afraid it's impossible to test this code, the parameters are just to damn arcane for me, and I've been a programmer for over 30 years

Commants, Comments and more Comments are needed in this spagetti code :-(

I'm afraid you didn't even bother to take a look to the examples, parameters are really ugly I agree, I have never been so lucky to be a programmer not even a minute.

Just having ordinary works for ordinary people doing their best to carry on and give a decent live to my family.

Comments (not commants), Comments and more, or at least enough, Comments are easy to find in the examples.

You have all the right to express your disagreement with this thing, please help yourself.

Other people (dunno if they are programmers or not) have done wonderful things with it and that's enough for me to be happy I once dared to share shuch a spagetti thing.

Lots of love and success with your gold shiny code and projects.
Have a good day

Comments deleted.

I'd love to use this to make my own metric-sized hex bolts and nuts for a variety of non-load tasks, but having a problem trying to figure out the parameters within the openscad file.

module hex_screw(od,st,lf0,lt,rs,cs,df,hg,ntl,ntd)

od = outer diameter
df = hex head diameter
hg = hex head thickness

Everything else I can't figure out but I know I can get values for them based on the published standards if I can understand what they represent.

Hi, you may like to take a look to the examples script: polytests.scad
Hope it helps!

Dear AUbenc,
is there any guide for using the CUstomizer? I admit most of the settings I do not understand what they are, as I am completely new to it.

thanks anyway for sharing your work

Hi cyrus,
unfortunatelly, this thing was uploaded long before the Customizer was implemented.
I have no idea if it may work right or not via Customizer, the only thing I know is that it is not designed to do so.
This being said, you may like to try to download the examples script where you should be able to figure out the meaning of the parameters.

MAN!, you solved my problem in 5 minutes!. Great job with polyScrewThread_r1.scad. I'll use it in my project and will share the credits.
Thank you VERY MUCH!

The threaded rod example works great, all the other examples give me an Error in line 324, which doesn't exist in any combination of library lines and example lines. Where is the error?

The assign() is being deprecated and my skills are not quite up to the skill needed to parse what OpenSCAD is doing. How should the assign module be redesigned to work?

Never mind on the examples not working, the polytests.scad file is buggy, there were no ";" to end the statements on the other examples, plus the hex_nut module was misnamed hexa_nut.

Looks good! Just have to worry about them crashing the library when they disable "assign"

I don't know if I really get it...

Just downloaded the 2 scripts (examples and r1 version of the lib) and run 1 by one all the examples without other issue than the warnings in the console regarding the assign() module and the "triangles" in the polyhedron() module.

I don't remember how I did the library and, as far as it works, I don't think I gonna take a look to change anything.

Just for info, if the assign() modules look like... " assign( a = b ) " just replace the whole thing by " a = b; "
When there's more than one expression, use one new line for each of them.

The online OpenSCAD manual may be handy here ;-)

For the triangles, just do as stated in the warning.

Last but not least, when OpenSCAD complains about a line that doesn't look to make any sense, normally, there's something missing like the ";" at the end of the line, a closing bracket or whatever.

Good luck and don't forget to share your designs!

Comments deleted.

It would be nice if there was some sort of directions for using this somewhere. There's not a single comment in the entire source file. Am I supposed to simply intuit what "od,st,lf0,lt,rs,cs,df,hg,ntl,ntd" means? Lacking any documentaiton, this Thing, nice as it may be, is useless.

Dear Michele31415,

"It would be nice if there was some sort of directions for using this somewhere."
As per the 3rd statement in the instructions section: you are welcome to take a look into "polytests.scad".

"There's not a single comment in the entire source file."
Well, you are absolutely right here if you go ahead to the library itself, again there's the examples file to bring some light.

"Am I supposed to simply intuit what "od,st,lf0,lt,rs,cs,df,hg,ntl,ntd" means?"
No, you are not.

"Lacking any documentaiton, ..."
Hmmm... there's some documentation.

"... this Thing, nice as it may be, is useless."
Imho, things are never useless or useful, is the use the user gives to them which makes them usable or not.

Thanks a lot for your comment.

  1. thanks for this.
  2. Is there a function for making pointed screws?
  3. Thanks aubenc

Unfortunately not, this was just to make very simple "screwable things" with the limitations of the printers back in 2011 (in that time was very difficult to print overhangs over the 45 degrees)
Thanks a lot to you for your comment!

Thanks for the reply.

I've used this library a couple of times over the years and found it very helpful.

I was just looking to make a screw with that tapered to a point but realized I should look around before I create something myself (I'm tend to do that a lot, create things that have already been done, sigh).

I'll hunt a little longer and then jump in … how hard can it be … decreasing radii and scaling… :)

Thanks again, Urban

Thank you so much for making this! I really needed a 3mm screw so I downloaded the ex01 model and customized it to fit the holes in my creation!

Glad to know it helped, tanks for the comment!!

ERROR: CSG generation failed! (no top level object found)

Mmmmmm... not easy to help here because I don't know what you do (or what you don't).
You will indeed get this message if you try to render/compile something from:

  • any of the files named "polyThread... .scad" : the modules there are intended to be called from another ".scad" with all the required parameters.
  • "polytests.scad" : there's a few usage examples there. You need to uncomment the one you'd like to render/compile, to do so, just remove the "//" at the beginning of one line calling one of the library's modules.

Hope it helps

hey I tried a few prints. this is awesome work! It work great without supports (but with RAFT). The nuts and bolts begin to fit after about 30 minutes after the print. I believe this has something to do with the filament settling.

This is awesome... I just wish it would be easier to use. Printing connection elements is something that you don't see ofter so well done.

Thank you!
Unfortunately the customizer wasn't there where I uploaded this thing.

Also, shame on me, it's already a long time that I have (and I use it myself) a much better library, almost ready for the customizer, that does standard Metric/Unified sizes, it only requires to change the size to taste, default is M8 and you only need to change to taste, say 1/2" or M3, or 3/4" or...

Hope I will find the time to give it the last refinements and upload it.

Thanks again!

is there an explination of what each of your variables mean? or better yet, attach parameter input to stl output letting me screw (HA!) around with it myself?

Yes, the parameters are explained.... somewhere.........
Tip: take a look to the 3rd line of the text in the instructions tab ;-)

Is there any way to make a conical screw? Something I can use to drill sand.

Mmmmm... no, there's not. Sorry for that, this is just a very simple library to make basic shaped threads.
You may have better luck (?) with the library by syvwlch which is mentioned in the description...

how i can make 5/8"-11 hex screw? im not understand :(

Unfortunately you can't. Sorry for that.
You could do it by writing your own OpenSCAD script and using this thing as a library to help (?) with the threads. It is not a straight forward process wich is roughly described down in the comments.

Thanx, I used it to create a small M3 bolt. Didn't run very smooth but the thread is just enough to get a metal nut over it.

Thanks to you for using it!
M3 is quite a challenging size to be printed. Did you just use the OpenSCAD "as is" or as a library? I mean, this script is not meant to produce ISO thread profiles (there's a turnaround somewhere down in the comments).
Nice small M3 screw, thanks for uploading the pic!!

I tried to create a standard photography equipment screw (1/4'' UNC).
By comparing the output to an actual screw I found that I have to input 30° to actually get 60° flanks opening angles.
But anything below 31° crashes OpenSCAD. Wonder what's happening here.
Here are the parameters I tried:
hex_screw(25.41/4,25.4/20, 30 ,6,0.5,2,25.47/16-0.15,4,3, -1);

There is indeed a (few) bug(s) in the original library, please use the "_r1" version, it works fine for me with your code.

Together with the bug fix, I have changed the way the head of the screw is done, check it out! (it is still possible to use the "old shape" using "hex_screw_0(... )" module).

Nice screw btw!!

I have done a full cycle test: it renders, it compiles, it slices, it prints and it fits the screw mount in my cameras without issues! I can wait to see it uploaded so I will be able to click the "made one" and post the photo.

Thanks again

Wow that was quick.
It works Gr8 now :)
I was a bit afraid it wouldn't print because of the rather brutal overhangs, but I guess for a small diameter 1/4'' screw the small circle inward pulling forces counteracts that problem a bit.

I too did some mods on the screwhead I also chipped away a bit from the vertical edges. Sorry for letting you do the same work by not telling. Heres what I did: (i did cut away a little too less i think)

module hex_head(hg,df) // modified
cylinder(h=hg, r=df/2/sin(60), $fn=6, center=false);
cylinder(h=hg, r=df/2/sin(60)0.97, $fn=60, center=false);
hg, r1=df/2/sin(60)0.9+hg, r2=df/2/sin(60)0.9-hg, $fn=60, center=false);
translate([0,0,hg]) scale([1,1,-1])
cylinder(h=2hg, r1=df/2/sin(60)0.9+hg, r2=df/2/sin(60)*0.9-hg, $fn=60, center=false);

Nice! Smoothing sharp edges is always good.

However :))) for hex bolt-heads/nuts I like to let them sharp because tools have better grip, just my personal taste.

I tried your changes and they where not working, I just used hex_head(8,13). The reason was one of the computed values going into the negative realm... (6,13) worked like a charm.

I will not change the code again, if you like, you may take this other approach for the smoothing:

module hex_head(hg,df)

x0=0; x1=df/2; x2=rd1;

y0=0; y1=rd0-(df/2); y2=hg-y1; y3=hg;

cylinder(h=hg, r=rd0, $fn=6, center=false);

rotate_extrude(convexity=10, $fn=6*round(df*PI/6/0.5))
polygon([ [x0,y0],[x1,y0],[x2,y1],[x2,y2],[x1,y3],[x0,y3] ]);


...just decrease/increase the 0.25 in rd1 to decr/incr the smoothing

Jep, I recognized that <0 problem right after posting - stupid me :)

Well, I'm afraid I did the same: too quick! :( :)

My changes as in the "_r1" version should work but may have unwanted results if the thickness of the hex block is too small :(
the code in the comment above will just fail in the same circumstances (thin hex block).

Anyway, this is an old thing asking for some changes, it was done when a 45 degs overhang was possible but not so easy and "fine res" was about 0.35mm for the layer height.

I may come soon with a customizer friendly new thing (from end to end)

Wow that was quick.
It works now :)
I was a bit afraid it wouldn't print because of the rather brutal overhangs, but I guess for a small diameter 1/4'' screw the small circle inward pulling forces counteracts that problem a bit.

I too did some mods on the screwhead - I also chipped away a bit from the edges. Sorry for letting you do the same work by not telling. Heres what I did:

module hex_head(hg,df) // modified
cylinder(h=hg, r=df/2/sin(60), $fn=6, center=false);
cylinder(h=hg, r=df/2/sin(60)0.97, $fn=60, center=false);
hg, r1=df/2/sin(60)0.9+hg, r2=df/2/sin(60)0.9-hg, $fn=60, center=false);
translate([0,0,hg]) scale([1,1,-1])
cylinder(h=2hg, r1=df/2/sin(60)0.9+hg, r2=df/2/sin(60)*0.9-hg,$fn=60, center=false);

hmmmmm... curious... I tried myself and got the same results, aaaargh!!
I'll take a look see what happens here.
Sorry for the trouble and thank you very much to report this!

mayb i'm not getting somthing - the model does not compile

do you have a example parameters for how to call the functions.

just to get it started?

polytests.scad contains some examples. It's true that this thing doesn't render (or not nicely) and may take some time to compile but when you get used to it, it works quite good :-D

Neat, I'll give that a try. I haven't had a chance to try the 0.75 pitch (that might be too aggressive), but I did print a 1.27mm pitch from your libarry with SLS, and that part actually turned out great.

You might want to take a look at these modules for creating ISO-standard threads: http://dkprojects.net/openscad-threadshttp://dkprojects.net/openscad...

If they work well enough perhaps they could be combined with your modules.

I couldn't seem to get your english_thread_tap to work...

The examples would be more meaningful if you modeled standard threads per specifications... like an ISO metric thread...

Right, however... the profile of the trheads I'm using is not meeting the ISO standard and to do it properly, I should have add even more parameters :-(

Most of the parameters of this thing are there to make the threads printable using almost any printer (like my very low res bot1334) not to make bolts and nuts that meet any standards.

I'll try to give a little bit more of light to the parameters bellow but it's a long answer so feel free to skip
it ;-)

... long answer, sorry...

I did this thing to be able to print using a CupcakeCNC with a home made hot-end and the stock MK4 DC geared filament feeder, hard to get layer height under 0.35mm. Impossible to print a M3, M5 or even a working M8.

To print something close to the standards (met
ric or, I guess that it should also work with imperial) you just need to care about few of the parameters, for example, there are 2 ISO sizes for a M8, M8x1.0 and M8x1.25, just set the diameter parameter to 8 (*) and the (I think I call it) step to 1 or 1.25.

(*) You'll need to let a gap between nu
t and bolt, I use to set the bolt to the std size, in this case 8, and add the gap to the nut, i.e. 8.5. You are free to do the opposite, i.e. bolt:7.5
amp; nut:8 or distribute the gap evenly or not between both, i.e bolt:7.7
amp; nut 8.2.

For the hex head of the bolts or dimensions for the nut... well, again is only a cople of parameters, distance between flats, usually 13mm (for the M8 example) and thickness (I think I call it height) which if I'm not wrong, the std is something like 5.6.

Here I used the distance between flats (i
nstead of the diameter or distance between opposite edges) just because is the size used for the tools. Be aware that it's too easy to break them when using tools.

... alternatives ...

At the time this thing was uploaded there was already another screw library closer (in shape) to the ISO std: th
http://ingiverse.com/thing:8793ingiverse.com/thing:8793 syvwlch.

At the time I'm writting this answer there's a new thing that promises ISO standars (I have not checked myself so I cannot tell): http://www.thingiverse.com/thing:27183http://www.thingiverse.com/thi... by TrevM

Screw Library
by syvwlch
OpenSCAD ISO metric thread library / functions
by TrevM


Just kidding. Explanations are good.

I'm going by the Wikipedia explanation of the metric specifications:


According to that doc, for a hypothetical M22x0.75 thread, I would want:

Nominal Diameter: 22mm
Pitch: 0.75

screw_thread(22 + (cos(
30) * 0.75 / 8), 0.75, 60, whatever, whatever, whatever)

Not sure if their notion of the "degrees" is the same for your model and theirs, hence my questions.

That, I'm assuming, is the basic metric thread shape, with the exception of the flats, which seemingly would be a union and a difference ope
ration. I.e. for a rod, it's a difference between the screw and a tube of inner diameter 22-(cos(30)0.75 1/8), and a union with a cylinder of outer diameter 22-(cos(30)0.753/4).

It would seem that this could just be a function or a switch which "makes it metric", and it only takes the same t
wo parameters as screw itself.

If I knew more about Openscad I'd do it myself... but then again, if I did, I wouldn't need to be looking at someone else's libraries ;)

That Wikipedia page is what made me do it the way I did it.

One of the reasons was the overhang, in that time more than 45 degrees of overhang was quite impossible without support.

For the external edge I would use Intersection (instead of diff) and I would be careful with the faceting of the cylinders used for the boolean operations (to match the resolu
tion of the thread).

I'm not sure if a pitch of 0.75 will print fine, do post a picture if you try it pleaaaseeeee!! (no mather if it's success or fail :-) ). I may be wrong but, from my point of view, to get a reliable ISO profile you need to fit at least 8 layers of material into the pitch value
and that's a layer height under the 0.1mm !!

Also worth to be mentioned, this library is already using a lot of boolean operations (and not so well done) and now we'll ask OpenSCAD to perform another couple of booleans (over the previous ones)... hope you have the patience or something else to do w
hile waiting for OpenSCAD to compile the result :-D

Here is how I would try a ISO profile with this library...


Ms=22; // Metric Size
Pt=0.75; // Pitch

ln=10*Pt; // Length, 10 times the Pitch in this example
rs=1.5; // Resolution
// (aprox. one face every "value"mm of the perimeter)

Od=Ms+2Pttan(30)/8; // Outer diameter to use in the
// library module

ICr=Ms/2; // Intersection Cylinder d
UCr=Od/2-5Pttan(30)/4; // Union Cylinder diameter

fno=Od*PI/rs; // Number of faces to use for the
// boolean cylinders

module ISO_like_thread();
cylinder(h=ln, r=ICr, $fn=fno, center=false);

        screw_thread(   Od, // Outer diameter of the thre

Pt, // Step
30, // Degrees
ln, // Length (Z) of the tread
rs, // Resolution
1); // Top end countersunk

        cylinder(h=ln, r=UCr, $fn=fno, center=false);


I just printed it and I couldn't feet the nut and under preasure the bolt broke. :(

I'm sorry to hear that :(

This thing can indeed be a little bit tricky to print and may require "special tunning" of the settings or, another alternative is to use the scad and change the gap between nut and bolt.

I've not experience with PLA (which seems to be what you are using looking at your made things) but, for what I have read, PLA may make this thing even more difficult.

A high infill will make the bolt stronger but may reduce the gap. If they don't fit loose enough the screw/bolt may break too easily, so it's better to tweak scad parameters or print settings but it's too difficult to tell you what to change in the print profile (take a look at the photo with the red background above).

If you still like to try :) I suggest to take a look to
a href="http://www.thingiverse.com/thing:9095http://www.thingiverse.com/thi..."
thing 9095
It looks like many people have had better luck there ;)

BTW, thanks a lot for trying and let us know how it went!

Knurled surface finishing library
by aubenc

i love this, thank you!

Glad you like it! Thanks

This is especially good for building electro-magnetic motors, as they don't disturb the fields... above hundreds of other practical or decorative things of course ;)

that looks like an amazing print, well done! :)

Thank you!

To be honest, if bot1334 did it, any other cupcake can do it. Believe it or not, mine is far to be fine tuned and we are soooo happy printing things :-D