Add option to just print either body or lid

This commit is contained in:
maride 2018-01-27 18:09:04 +01:00
parent 9351c7760b
commit 0781eb1972

View File

@ -10,7 +10,7 @@
// generate_box(INNER_X, INNER_Y, INNER_Z, WALLSIZE, OVERLAP_Z); // generate_box(INNER_X, INNER_Y, INNER_Z, WALLSIZE, OVERLAP_Z);
// generate_box(INNER_X, INNER_Y, INNER_Z, WALLSIZE, OVERLAP_Z, [NOTCH_WIDTH, NOTCH_DEPTH]); // generate_box(INNER_X, INNER_Y, INNER_Z, WALLSIZE, OVERLAP_Z, [NOTCH_WIDTH, NOTCH_DEPTH]);
// Small example for a box width inner size 60x60x30, wall size 4, wall-sized overlap and a small notch: // Small example for a box width inner size 60x60x30, wall size 4, wall-sized overlap and a small notch:
generate_box(60, 60, 30, 4, 4, 5, 2); generate_box(60, 60, 30, 4, 4, 5, 2, body=true, lid=true);
/* /*
* [2] Include & Generate * [2] Include & Generate
* Copy and paste this line to another file: */ * Copy and paste this line to another file: */
@ -28,22 +28,15 @@ generate_box(60, 60, 30, 4, 4, 5, 2);
* Idea behind the notch: you can secure the box lid with e.g. a rubber band * Idea behind the notch: you can secure the box lid with e.g. a rubber band
*/ */
module generate_box(INNER_X, INNER_Y, INNER_Z, WALLSIZE, OVERLAP_Z, NOTCH_WIDTH, NOTCH_DEPTH) { module generate_box(INNER_X, INNER_Y, INNER_Z, WALLSIZE, OVERLAP_Z, NOTCH_WIDTH, NOTCH_DEPTH, BODY, LID) {
difference() { difference() {
union() { union() {
// The main box if(body) {
difference() { generate_main_box(INNER_X, INNER_Y, INNER_Z, WALLSIZE);
cube([INNER_X+WALLSIZE*2, INNER_Y+WALLSIZE*2, INNER_Z+WALLSIZE*2]);
translate([WALLSIZE, WALLSIZE, WALLSIZE])
cube([INNER_X, INNER_Y, INNER_Z+WALLSIZE]);
} }
if(lid) {
// Box lid translate([WALLSIZE, WALLSIZE, INNER_Z+WALLSIZE*4])
translate([WALLSIZE, WALLSIZE, INNER_Z+WALLSIZE*4]) { generate_lid(INNER_X, INNER_Y, OVERLAP_Z, WALLSIZE);
translate([0.5, 0.5, 0])
cube([INNER_X-1, INNER_Y-1, OVERLAP_Z]);
translate([-WALLSIZE, -WALLSIZE, OVERLAP_Z])
cube([INNER_X+WALLSIZE*2, INNER_Y+WALLSIZE*2, WALLSIZE]);
} }
} }
@ -56,3 +49,20 @@ module generate_box(INNER_X, INNER_Y, INNER_Z, WALLSIZE, OVERLAP_Z, NOTCH_WIDTH,
} }
} }
} }
// The main box
module generate_main_box(INNER_X, INNER_Y, INNER_Z, WALLSIZE) {
difference() {
cube([INNER_X+WALLSIZE*2, INNER_Y+WALLSIZE*2, INNER_Z+WALLSIZE*2]);
translate([WALLSIZE, WALLSIZE, WALLSIZE])
cube([INNER_X, INNER_Y, INNER_Z+WALLSIZE]);
}
}
// Box lid
module generate_lid(INNER_X, INNER_Y, OVERLAP_Z, WALLSIZE) {
translate([0.5, 0.5, 0])
cube([INNER_X-1, INNER_Y-1, OVERLAP_Z]);
translate([-WALLSIZE, -WALLSIZE, OVERLAP_Z])
cube([INNER_X+WALLSIZE*2, INNER_Y+WALLSIZE*2, WALLSIZE]);
}