acorn: add option to control generated parts
authorClinton Ebadi <clinton@unknownlamer.org>
Sat, 11 Nov 2017 19:37:07 +0000 (14:37 -0500)
committerClinton Ebadi <clinton@unknownlamer.org>
Sat, 11 Nov 2017 19:37:07 +0000 (14:37 -0500)
Override acorn_parts on the command line to generate individual parts
of the acorn. Default is to generate all parts.

e.g. `openscad -Dacorn_parts='["body"]' acorn_threads.scad' to only
generate the body.

acorn/acorn-threads.scad

index 1abc99e..50eb524 100644 (file)
@@ -5,10 +5,15 @@ use <screw_threads.scad> // http://www.thingiverse.com/thing:1686322
 
 AUTO_CALCULATE = -1;
 
 
 AUTO_CALCULATE = -1;
 
+acorn_parts = [ "body", "cap", "gasket" ];
+
 internal_thread_tolerance = 0.3;
 external_thread_tolerance = 0.2;
 thread_angle = 50;
 
 internal_thread_tolerance = 0.3;
 external_thread_tolerance = 0.2;
 thread_angle = 50;
 
+
+function contains (x, lst) = len([ for (i = lst) if (x == i) i]) > 0;
+
 module acorn (thread_pitch = 3.0,
              thread_size = 2.5,
              thread_height = 3.5,
 module acorn (thread_pitch = 3.0,
              thread_size = 2.5,
              thread_height = 3.5,
@@ -98,9 +103,12 @@ module acorn (thread_pitch = 3.0,
      }
 
      module nuts () {
      }
 
      module nuts () {
-         translate ([outer_d+10, 0, 0,])  nut ();
-         cap ();
-         translate ([-(outer_d+10), 0, 0,])  gasket ();
+         if (contains ("body", acorn_parts))
+              translate ([outer_d+10, 0, 0,])  nut ();
+         if (contains ("cap", acorn_parts))
+              cap ();
+         if (contains ("gasket", acorn_parts))
+             translate ([-(outer_d+10), 0, 0,])  gasket ();
      }
 
      nuts ();
      }
 
      nuts ();