
Metric thread and screw library
thingiverse
I needed a large screw thread and nut to fit over a tube. There are excellent libraries for this, such as https://www.thingiverse.com/thing:8793 and https://www.thingiverse.com/thing:193647 , but I thought it would be fun to build my own. This library lets you make metric screws. The thread geometry follows metric standards, as described in https://www.machiningdoctor.com/charts/metric-thread-charts/#c-mc . See also http://www.apollointernational.in/iso-metric-thread-chart.php for ISO thread tolerances. Before I lead you astray, I should mention that OpenScad libraries page (https://openscad.org/libraries.html) has a number of libraries that provide various screws and nuts. In particular, check out BOSL2, BOLTS and threads.scad module. I haven't tried any of them, but they are an excellent place to look if this library doesn't do what you need. Or even if it does! Idealized metric thread cross-section is an equilateral triangle, where one triangle side is laid along the screw axis (I assume vertical axis). The triangle outward peak is trimmed, so the actual thread cross-section is a trapeze. The nominal thread diameter (the "M" value) is to the trimmed trapeze face, but the actual thread is slightly undersized. UPDATE 8/17/22: I've added "angle" parameter that allows for non-metric thread geometries. It defaults to 60 degrees, which is metric. Smaller angles yield deeper thread, larger angles yield shallower thread. For 3D printing, we need to modify the original geometry, so we provide parameters to modify the diameter and also trim and fill. In general, you should be able to leave the trim and fill as default and just modify the diam_adj. The library contains five modules: <ul> <li>screw_segment - builds a screw segment and contains all the thread logic. </li> <li> nut_core - builds a inward-facing thread encased in a thin outer wall. Thread is built by diffing an appropriate screw segment from a cylinder. </li> <li> hex_bolt - builds a hex bolt with the part of the body optionaly not being threaded. </li> <li> hex_nut - builds a hex nut. </li> <li> wing_nut - builds a wing nut. </li> </ul> If you run openscad on this file, it will build example bolts and nuts for sizes M4, M5, M6, M8 and M10. Each module takes two or three positional parameters and a number of optional named parameters. The positional parameters are the same as are used to specify metric screw sizes: diameter, pitch and length, all in mm. The length parameter is passed to screw and bolt modules only, nuts infer the length from the hex_thickness parameter. We use named hex_thickness to make it clear that it can be left out, in which case the thickness (and the corresponding thread length) is computed automatically. Named parameters refine and modify the screw shape as follows: Common parameters: fn = 50 : polyhedron segments per turn diam_adj = +/-0.1 : nominal outer diameter change (changes backlash) negative for screw, positive for nut trunc = -1 : how much to trim the outer peak. -1 : h/4 fill = -1 : how much to fill the inner valley. -1 : h/8 angle = 60 : thread cross-section triangle outer thread angle. Metric threads have equilateral triangle cross section before any trimming, so this is 60 degrees. Smaller angles yield deeper thread, larger angles yield shallower thread. chamfer_top = true : chamfer the screw or nut on the top chamfer_bottom = false : chamfer the screw or nut on the bottom screw_segment only: lead_top = true : lead thread (recessing into interior) on the top lead_bottom = false : lead thread on the bottom hex_bolt only: thread_length = -1 : thread length in mm, -1 is equal to bolt length hex_bolt, hex_nut and wing_nut: hex_width = -1 : hex wrench size in mm, -1 for auto hex_thickness = -1 : head (or nut) thickness in mm, -1 for auto We assume the screw is built vertically, so "bottom" and "top" refer to the two screw ends. We follow the ISO logic, where the outer screw diameter is to the outer face, namely after the trim has been subtracted. You should be able to leave trim and fill as defaults and only change diag_adj as needed. In general, screws should be shrunk a little and bolts expanded a little, to account for the fact that the 3D prints are not as sharp as machined metal. Run by itself, the code can produce bolt and nut combination for each of the sizes M3, M4, M5, M6, M8 and M10. On my printer, using PLA, diam_adj varies from -0.7 to -0.3 for bolts and stays at 0.3. for nuts. You may have to change this depending on your screw size, print material and print quality. The following parameters worked for me (see print settings below), but you you should test what works on your printer. These are for M5, M6, M8 and M10. M4 bolt was too spindly for my liking, but I include M4 nut parameters. In all cases, the bolts and nuts fit both each other and the corresponding metal metric screws and nuts. hex_bolt( 5, 0.8, 15, diam_adj=-0.5, fn=50, thread_length=-1, hex_thickness=5 ) ; hex_bolt( 6, 1.0, 15, diam_adj=-0.5, fn=50, thread_length=-1, hex_thickness=-1 ) ; hex_bolt( 8, 1.25, 15, diam_adj=-0.7, fn=50, thread_length=-1, hex_thickness=-1 ) ; hex_bolt( 10, 1.5, 25, diam_adj=-0.7, fn=50, thread_length=15, hex_thickness=-1 ) ; hex_nut( 4, 0.7, diam_adj=0.3, fn=50, hex_thickness=5 ) ; hex_nut( 5, 0.8, diam_adj=0.3, fn=50, hex_thickness=5 ) ; hex_nut( 6, 1.0, diam_adj=0.3, fn=50, hex_thickness=-1 ) ; hex_nut( 8, 1.25, diam_adj=0.3, fn=50, hex_thickness=-1 ) ; hex_nut( 10, 1.5, diam_adj=0.3, fn=50, hex_thickness=8 ) ; Set the true/false flags at the start of the code to select what to render. By default, all sizes except M3 are built. M3 requires very good print quality for the screw (nut is OK, but then even a blank cylinder of proper size works as a M3 nut), and the screw is too spindly to be of much use. The algorithm to generate the thread spiral is slightly different than the one used in the other libraries I've seen. Instead of building a polyhedron for each thread segment, the whole spiral is a single polyhedron. The segments are the same under both algorithms, it's just a different way of assembling the whole spiral. Notionally, one would hope that this is a smidge more efficient, but the downside is that openscad has trouble showing the thread built this way in the preview. It will render it correctly, so you might prefix the thread calls with the <code>render()</code> operator, or just hit F6 early and often in the user interface. I've put in a few comments to make it easier to understand what is going on. You can find the current version of this code, as well as my other openscad primitives, on <a href="https://github.com/imageguy/openscad_primitives">GitHub</a>
With this file you will be able to print Metric thread and screw library with your 3D printer. Click on the button and save the file on your computer to work, edit or customize your design. You can also find more 3D designs for printers on Metric thread and screw library.