From 39057113bc75f596d066be0f413c08a3c6e0e425 Mon Sep 17 00:00:00 2001 From: maride Date: Wed, 22 Nov 2017 21:57:25 +0100 Subject: [PATCH] Translate generator to module --- Box_Type2_Generator.scad | 74 +++++++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 31 deletions(-) diff --git a/Box_Type2_Generator.scad b/Box_Type2_Generator.scad index ed15647..3358f4c 100644 --- a/Box_Type2_Generator.scad +++ b/Box_Type2_Generator.scad @@ -1,45 +1,57 @@ -INNER_X=60; -INNER_Y=60; -INNER_Z=30; -WALLSIZE=4; - -OVERLAP_Z=WALLSIZE; /* + * hello.scad! :) + * It is possible to use this generator in two ways: + * - Simply, generate boxes (see [1]) + * - Include this file to generate boxes in other SCAD files (see [2]) + * + * [1] Generate boxes + * Uncomment one of the three following lines: */ +// generate_box(INNER_X, INNER_Y, INNER_Z, WALLSIZE); +// 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]); +// 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); +/* + * [2] Include & Generate + * Copy and paste this line to another file: */ +// use Box_Type2_Generator.scad; + +/* Some explanations to the parameters: + * === OVERLAP_Z === * The size of the inner overlap size * Set OVERLAP_Z to 0 to deactivate the overlap area at all. * In most cases, it should be enough to set it to WALLSIZE. - */ - -NOTCH_WIDTH=5; -NOTCH_DEPTH=2; -/* + * + * === NOTCH_DEPTH === * NOTCH_DEPTH < WALLSIZE for obvious reasons. * Set NOTCH_DEPTH to 0 to deactivate the notch at all. * 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) { + difference() { + union() { + // The main box + 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]); + } -difference() { - union() { - // The main box - 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 + translate([WALLSIZE, WALLSIZE, INNER_Z+WALLSIZE*4]) { + cube([INNER_X, INNER_Y, OVERLAP_Z]); + translate([-WALLSIZE, -WALLSIZE, OVERLAP_Z]) + cube([INNER_X+WALLSIZE*2, INNER_Y+WALLSIZE*2, WALLSIZE]); + } } - // Box lid - translate([WALLSIZE, WALLSIZE, INNER_Z+WALLSIZE*4]) { - cube([INNER_X, INNER_Y, OVERLAP_Z]); - translate([-WALLSIZE, -WALLSIZE, OVERLAP_Z]) - cube([INNER_X+WALLSIZE*2, INNER_Y+WALLSIZE*2, WALLSIZE]); + // The notch + union() { + translate([INNER_X/2-NOTCH_WIDTH/2+WALLSIZE, 0, 0]) + cube([NOTCH_WIDTH, NOTCH_DEPTH, INNER_Z+WALLSIZE*6]); + translate([INNER_X/2-NOTCH_WIDTH/2+WALLSIZE, INNER_Y+WALLSIZE+NOTCH_DEPTH, 0]) + cube([NOTCH_WIDTH, NOTCH_DEPTH, INNER_Z+WALLSIZE*6]); } } - - // The notch - union() { - translate([INNER_X/2-NOTCH_WIDTH/2+WALLSIZE, 0, 0]) - cube([NOTCH_WIDTH, NOTCH_DEPTH, INNER_Z+WALLSIZE*6]); - translate([INNER_X/2-NOTCH_WIDTH/2+WALLSIZE, INNER_Y+WALLSIZE+NOTCH_DEPTH, 0]) - cube([NOTCH_WIDTH, NOTCH_DEPTH, INNER_Z+WALLSIZE*6]); - } } \ No newline at end of file