Last active
September 4, 2022 06:33
-
-
Save Hexagon/9484870 to your computer and use it in GitHub Desktop.
Parametric OpenSCAD distance/spacer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ------------------------------------------------------ | |
// User configurable parameters | |
// ------------------------------------------------------ | |
spacer_height = 15; // Height in mm | |
m_standard_size = 4; // M-standard (M1.6 -- M16) is currently supported, 4 = M4, 1.6 = M1.6 | |
undersize_for_threading = true; // True use the appropriate undersize for postprocessing with a tap, | |
// false makes a pure spacer | |
hex_shape = true; // True forms a hexagonal spacer(nut), false makes a round outer perimiter | |
wall_thickness = 3; // Indicates the maximum wall thickness in case of an | |
// hexagonal outer perimiter | |
// NOTE!: If you intend to use undersize for threading with large diameters (>M6), you'll have to add a | |
// couple of inner perimiters while slicing. Thread depth radius of M6 is 1mm, M16 is 2mm | |
// ----------------------------------------------------- | |
// No need to edit below this | |
// ----------------------------------------------------- | |
outer_diameter = m_standard_size + wall_thickness; | |
m_hole_size = ( m_standard_size == 1.6 ) ? 1.25 : | |
( m_standard_size == 1.8 ) ? 1.45 : | |
( m_standard_size == 2 ) ? 1.6 : | |
( m_standard_size == 2.2 ) ? 1.75 : | |
( m_standard_size == 2.5 ) ? 2.05 : | |
( m_standard_size == 3 ) ? 2.5 : | |
( m_standard_size == 3.5 ) ? 2.9 : | |
( m_standard_size == 4 ) ? 3.3 : | |
( m_standard_size == 5 ) ? 4.2 : | |
( m_standard_size == 6 ) ? 5 : | |
( m_standard_size == 7 ) ? 6 : | |
( m_standard_size == 8 ) ? 6.8 : | |
( m_standard_size == 9 ) ? 7.8 : | |
( m_standard_size == 10 ) ? 8.5 : | |
( m_standard_size == 11 ) ? 9.5 : | |
( m_standard_size == 12 ) ? 10.3 : | |
( m_standard_size == 14 ) ? 12 : | |
( m_standard_size == 16 ) ? 14 : m_standard_size; | |
m_hole_final_size = ( undersize_for_threading == true ) ? m_hole_size : m_standard_size; | |
difference() { | |
if ( hex_shape == true ) { | |
cylinder( | |
h = spacer_height, | |
r=outer_diameter/2, | |
$fn=6 | |
); | |
} else { | |
cylinder( | |
h = spacer_height, | |
r=outer_diameter/2, | |
$fs=1 | |
); | |
} | |
translate([0,0,-1]) cylinder( | |
h = spacer_height+2, | |
r=m_hole_final_size/2+0.1, | |
$fs=1 | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment