Translate generator to module

This commit is contained in:
maride 2017-11-22 21:57:25 +01:00
parent a1df26afeb
commit 39057113bc

View File

@ -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]);
}
}