Butt_box made more flexible with extra parameters.

This commit is contained in:
Chris Palmer 2019-08-18 14:18:21 +01:00
parent be3999ed3e
commit 312f12dfd0
2 changed files with 104 additions and 94 deletions

View File

@ -27,6 +27,10 @@
//! A list specifies the internal dimensions, screw type, top, bottom and side sheet types and the block //! A list specifies the internal dimensions, screw type, top, bottom and side sheet types and the block
//! maximum spacing. //! maximum spacing.
//! //!
//! * An optional name can be specified to allow more then one box in a project.
//! * An optional list of fixing blocks to be omitted can be given.
//! * Star washers can be omitted by setting the 11th parameter to false.
//!
//! Uses [fixing blocks](#fixing_block) and [corner blocks](#corner_block). //! Uses [fixing blocks](#fixing_block) and [corner blocks](#corner_block).
// //
@ -34,17 +38,20 @@ use <fixing_block.scad>
use <corner_block.scad> use <corner_block.scad>
use <../utils/maths.scad> use <../utils/maths.scad>
function bbox_screw(type) = type[0]; //! Screw type for corner blocks function bbox_screw(type) = type[0]; //! Screw type for corner blocks
function bbox_sheets(type) = type[1]; //! Sheet type for the sides function bbox_sheets(type) = type[1]; //! Sheet type for the sides
function bbox_base_sheet(type)= type[2]; //! Sheet type for the base function bbox_base_sheet(type) = type[2]; //! Sheet type for the base
function bbox_top_sheet(type) = type[3]; //! Sheet type for the top function bbox_top_sheet(type) = type[3]; //! Sheet type for the top
function bbox_span(type) = type[4]; //! Maximum span between fixing blocks function bbox_span(type) = type[4]; //! Maximum span between fixing blocks
function bbox_width(type) = type[5]; //! Internal width function bbox_width(type) = type[5]; //! Internal width
function bbox_depth(type) = type[6]; //! Internal depth function bbox_depth(type) = type[6]; //! Internal depth
function bbox_height(type) = type[7]; //! Internal height function bbox_height(type) = type[7]; //! Internal height
function bbox_name(type) = type[8] ? type[8] : "bbox"; //! Optional name if there is more than one box in a project
function bbox_skip_blocks(type)= type[9] ? type[9] : []; //! List of fixing blocks to skip, used to allow a hinged panel for example
function star_washers(type) = type[10] ? type[10] : is_undef(type[10]); //! Set to false to remove star washers.
module bbox_shelf_blank(type) { //! 2D template for a shelf module bbox_shelf_blank(type) { //! 2D template for a shelf
dxf("bbox_shelf"); dxf(str(bbox_name(type), "_shelf"));
sheet_2D(bbox_sheets(type), bbox_width(type), bbox_depth(type), 1); sheet_2D(bbox_sheets(type), bbox_width(type), bbox_depth(type), 1);
} }
@ -60,18 +67,8 @@ function corner_block_positions(type) = let(
y = [-1,-1,1,1][corner] y = [-1,-1,1,1][corner]
) translate([x * (width / 2), y * (depth / 2), z * height / 2]) * ) translate([x * (width / 2), y * (depth / 2), z * height / 2]) *
rotate([z > 0 ? 180 : 0, 0, corner * 90 + (z > 0 ? 90 : 0)]) rotate([z > 0 ? 180 : 0, 0, corner * 90 + (z > 0 ? 90 : 0)])
]; ];
module corner_block_positions(type) {
bt = sheet_thickness(bbox_base_sheet(type));
tt = sheet_thickness(bbox_top_sheet(type));
for(p = corner_block_positions(type))
let($thickness = transform([0, 0, 0], p).z > 0 ? tt : bt)
multmatrix(p)
children();
}
function corner_holes(type) = [for(p = corner_block_positions(type), q = corner_block_holes(bbox_screw(type))) p * q]; function corner_holes(type) = [for(p = corner_block_positions(type), q = corner_block_holes(bbox_screw(type))) p * q];
function fixing_block_positions(type) = let( function fixing_block_positions(type) = let(
@ -84,36 +81,28 @@ function fixing_block_positions(type) = let(
dspans = floor(depth / span), dspans = floor(depth / span),
dspan = depth / (dspans + 1), dspan = depth / (dspans + 1),
hspans = floor(height / span), hspans = floor(height / span),
hspan = height / (hspans + 1) hspan = height / (hspans + 1),
skips = bbox_skip_blocks(type)
) )
[ [
for(i = [0 : 1 : wspans - 1], y = [-1, 1], z = [-1, 1]) for(i = [0 : 1 : wspans - 1], y = [-1, 1], z = [-1, 1])
translate([(i - (wspans - 1) / 2) * wspan, y * depth / 2, z * height / 2]) * if(!in(skips, [0, y, z]))
rotate([0, z * 90 + 90, y * 90 + 90]), translate([(i - (wspans - 1) / 2) * wspan, y * depth / 2, z * height / 2]) *
rotate([0, z * 90 + 90, y * 90 + 90]),
for(i = [0 : 1 : dspans - 1], x = [-1, 1], z = [-1, 1]) for(i = [0 : 1 : dspans - 1], x = [-1, 1], z = [-1, 1])
translate([x * width / 2, (i - (dspans - 1) / 2) * dspan, z * height / 2]) * if(!in(skips, [x, 0, z]))
rotate([0, z * 90 + 90, x * 90]), translate([x * width / 2, (i - (dspans - 1) / 2) * dspan, z * height / 2]) *
rotate([0, z * 90 + 90, x * 90]),
for(i = [0 : 1 : hspans - 1], x = [-1, 1], y = [-1, 1]) for(i = [0 : 1 : hspans - 1], x = [-1, 1], y = [-1, 1])
translate([x * width / 2, y * depth / 2, (i - (hspans - 1) / 2) * hspan]) * if(!in(skips, [x, y, 0]))
rotate([y > 0 ? 180 : 0, x * y * 90, 0]), translate([x * width / 2, y * depth / 2, (i - (hspans - 1) / 2) * hspan]) *
rotate([y > 0 ? 180 : 0, x * y * 90, 0]),
]; ];
function side_holes(type) = [for(p = fixing_block_positions(type), q = fixing_block_holes(bbox_screw(type))) p * q]; function side_holes(type) = [for(p = fixing_block_positions(type), q = fixing_block_holes(bbox_screw(type))) p * q];
module fixing_block_positions(type) {
t = sheet_thickness(bbox_sheets(type));
bt = sheet_thickness(bbox_base_sheet(type));
tt = sheet_thickness(bbox_top_sheet(type));
h = bbox_height(type) / 2 - 1;
for(p = fixing_block_positions(type))
let(z = transform([0, 0, 0], p).z, $thickness = z > h ? tt : z < -h ? bt : t)
multmatrix(p)
children();
}
module drill_holes(type, t) module drill_holes(type, t)
for(list = [corner_holes(type), side_holes(type)], p = list) for(list = [corner_holes(type), side_holes(type)], p = list)
let(q = t * p) let(q = t * p)
@ -122,7 +111,7 @@ module drill_holes(type, t)
drill(screw_clearance_radius(bbox_screw(type)), 0); drill(screw_clearance_radius(bbox_screw(type)), 0);
module bbox_base_blank(type) { //! 2D template for the base module bbox_base_blank(type) { //! 2D template for the base
dxf("bbox_base"); dxf(str(bbox_name(type), "_base"));
difference() { difference() {
sheet_2D(bbox_base_sheet(type), bbox_width(type), bbox_depth(type), 1); sheet_2D(bbox_base_sheet(type), bbox_width(type), bbox_depth(type), 1);
@ -132,7 +121,7 @@ module bbox_base_blank(type) { //! 2D template for the base
} }
module bbox_top_blank(type) { //! 2D template for the top module bbox_top_blank(type) { //! 2D template for the top
dxf("bbox_top"); dxf(str(bbox_name(type), "_top"));
t = sheet_thickness(bbox_sheets(type)); t = sheet_thickness(bbox_sheets(type));
@ -144,36 +133,40 @@ module bbox_top_blank(type) { //! 2D template for the top
} }
} }
module bbox_left_blank(type) { //! 2D template for the left side function subst_sheet(type, sheet) =
dxf("bbox_left"); let(s = bbox_sheets(type))
sheet ? assert(sheet_thickness(sheet) == sheet_thickness(s)) sheet : s;
module bbox_left_blank(type, sheet = false) { //! 2D template for the left side
dxf(str(bbox_name(type), "_left"));
t = sheet_thickness(bbox_sheets(type)); t = sheet_thickness(bbox_sheets(type));
bb = sheet_thickness(bbox_base_sheet(type)); bb = sheet_thickness(bbox_base_sheet(type));
difference() { difference() {
translate([-t / 2, -bb / 2]) translate([-t / 2, -bb / 2])
sheet_2D(bbox_sheets(type), bbox_depth(type) + t, bbox_height(type) + bb); sheet_2D(subst_sheet(type, sheet), bbox_depth(type) + t, bbox_height(type) + bb);
drill_holes(type, rotate([0, 90, 90]) * translate([bbox_width(type) / 2, 0])); drill_holes(type, rotate([0, 90, 90]) * translate([bbox_width(type) / 2, 0]));
} }
} }
module bbox_right_blank(type) { //! 2D template for the right side module bbox_right_blank(type, sheet = false) { //! 2D template for the right side
dxf("bbox_right"); dxf(str(bbox_name(type), "_right"));
t = sheet_thickness(bbox_sheets(type)); t = sheet_thickness(bbox_sheets(type));
bb = sheet_thickness(bbox_base_sheet(type)); bb = sheet_thickness(bbox_base_sheet(type));
difference() { difference() {
translate([t / 2, -bb / 2]) translate([t / 2, -bb / 2])
sheet_2D(bbox_sheets(type), bbox_depth(type) + t, bbox_height(type) + bb); sheet_2D(subst_sheet(type, sheet), bbox_depth(type) + t, bbox_height(type) + bb);
drill_holes(type, rotate([0, -90, 90]) * translate([-bbox_width(type) / 2, 0])); drill_holes(type, rotate([0, 90, 90]) * translate([-bbox_width(type) / 2, 0]));
} }
} }
module bbox_front_blank(type) { //! 2D template for the front module bbox_front_blank(type, sheet = false) { //! 2D template for the front
dxf("bbox_front"); dxf(str(bbox_name(type), "_front"));
t = sheet_thickness(bbox_sheets(type)); t = sheet_thickness(bbox_sheets(type));
bb = sheet_thickness(bbox_base_sheet(type)); bb = sheet_thickness(bbox_base_sheet(type));
@ -181,23 +174,23 @@ module bbox_front_blank(type) { //! 2D template for the front
difference() { difference() {
translate([0, (bt - bb) / 2]) translate([0, (bt - bb) / 2])
sheet_2D(bbox_sheets(type), bbox_width(type) + 2 * t, bbox_height(type) + bb + bt); sheet_2D(subst_sheet(type, sheet), bbox_width(type) + 2 * t, bbox_height(type) + bb + bt);
drill_holes(type, rotate([-90, 0, 0]) * translate([0, bbox_depth(type) / 2])); drill_holes(type, rotate([-90, 0, 0]) * translate([0, bbox_depth(type) / 2]));
} }
} }
module bbox_back_blank(type) { //! 2D template for the back module bbox_back_blank(type, sheet = false) { //! 2D template for the back
dxf("bbox_back"); dxf(str(bbox_name(type), "_back"));
bb = sheet_thickness(bbox_base_sheet(type)); bb = sheet_thickness(bbox_base_sheet(type));
t = sheet_thickness(bbox_sheets(type)); t = sheet_thickness(bbox_sheets(type));
difference() { difference() {
translate([0, -bb / 2]) translate([0, -bb / 2])
sheet_2D(bbox_sheets(type), bbox_width(type), bbox_height(type) + bb); sheet_2D(subst_sheet(type, sheet), bbox_width(type), bbox_height(type) + bb);
drill_holes(type, rotate([90, 0, 0]) * translate([0, -bbox_depth(type) / 2])); drill_holes(type, rotate([-90, 0, 0]) * translate([0, -bbox_depth(type) / 2]));
} }
} }
@ -208,8 +201,7 @@ module bbox_front(type) render_2D_sheet(bbox_sheets(type)) bbox_front_blank(type
module bbox_left(type) render_2D_sheet(bbox_sheets(type)) bbox_left_blank(type); //! Default left side, can be overridden to customise module bbox_left(type) render_2D_sheet(bbox_sheets(type)) bbox_left_blank(type); //! Default left side, can be overridden to customise
module bbox_right(type) render_2D_sheet(bbox_sheets(type)) bbox_right_blank(type); //! Default right side, can be overridden to customise module bbox_right(type) render_2D_sheet(bbox_sheets(type)) bbox_right_blank(type); //! Default right side, can be overridden to customise
module _bbox_assembly(type, top = true, base = true, left = true, right = true, back = true, front = true) //! The box assembly, wrap with a local copy without parameters module _bbox_assembly(type, top = true, base = true, left = true, right = true, back = true, front = true) { //! The box assembly, wrap with a local copy without parameters
assembly("bbox") {
width = bbox_width(type); width = bbox_width(type);
depth = bbox_depth(type); depth = bbox_depth(type);
height = bbox_height(type); height = bbox_height(type);
@ -219,43 +211,54 @@ assembly("bbox") {
bt = sheet_thickness(bbox_base_sheet(type)); bt = sheet_thickness(bbox_base_sheet(type));
tt = sheet_thickness(bbox_top_sheet(type)); tt = sheet_thickness(bbox_top_sheet(type));
corner_block_positions(type) function is_missing_screw(p) = p.y > depth / 2 - 1 ? !back : false;
fastened_corner_block_assembly(t, bbox_screw(type), $thickness);
fixing_block_positions(type) assembly(bbox_name(type)) {
fastened_fixing_block_assembly(t, bbox_screw(type), thickness2 = $thickness);
for(x = [-1, 1]) for(p = corner_block_positions(type))
translate([x * (width / 2 + t / 2 + eps + 25 * exploded()), 0]) let(q = transform([0, 0, 0], p), thickness = q.z > 0 ? tt : bt)
rotate([90, 0, x * 90]) multmatrix(p)
if(x > 0) { fastened_corner_block_assembly(is_missing_screw(q) && ((q.z > 0) != (q.x > 0)) ? 0 : t, bbox_screw(type), thickness,
if(right) is_missing_screw(q) && ((q.z > 0) == (q.x > 0)) ? 0 : t, star_washers = star_washers(type));
bbox_right(type);
h = height / 2 - 1;
for(p = fixing_block_positions(type))
let(q = transform([0, 0, 0], p), thickness = q.z > h ? tt : q.z < -h ? bt : t)
multmatrix(p)
fastened_fixing_block_assembly(is_missing_screw(q) ? 0 : t, bbox_screw(type), thickness2 = thickness, star_washers = star_washers(type));
for(x = [-1, 1])
translate([x * (width / 2 + t / 2 + eps + 25 * exploded()), 0])
rotate([90, 0, x * 90])
if(x > 0) {
if(right)
bbox_right(type);
}
else
if(left)
bbox_left(type);
for(y = [1, -1])
translate([0, y * (depth / 2 + t / 2 + eps + 25 * exploded())])
rotate([90, 0, y * 90 + 90])
if(y < 0) {
if(front)
bbox_front(type);
}
else
if(back)
bbox_back(type);
for(z = [-1, 1]) {
sheet_thickness = z > 0 ? tt : bt;
translate_z(z * (height / 2 + sheet_thickness / 2 + eps + 100 * exploded()))
if(z > 0) {
if(top)
bbox_top(type);
} }
else else
if(left) if(base)
bbox_left(type); bbox_base(type);
}
for(y = [-1, 1])
translate([0, y * (depth / 2 + t / 2 + eps + 25 * exploded())])
rotate([90, 0, y * 90 + 90])
if(y < 0) {
if(front)
bbox_front(type);
}
else
if(back)
bbox_back(type);
for(z = [-1, 1]) {
sheet_thickness = z > 0 ? tt : bt;
translate_z(z * (height / 2 + sheet_thickness / 2 + eps + 100 * exploded()))
if(z > 0) {
if(top)
bbox_top(type);
}
else
if(base)
bbox_base(type);
} }
} }

View File

@ -3168,6 +3168,10 @@ and mounted components.
A list specifies the internal dimensions, screw type, top, bottom and side sheet types and the block A list specifies the internal dimensions, screw type, top, bottom and side sheet types and the block
maximum spacing. maximum spacing.
* An optional name can be specified to allow more then one box in a project.
* An optional list of fixing blocks to be omitted can be given.
* Star washers can be omitted by setting the 11th parameter to false.
Uses [fixing blocks](#fixing_block) and [corner blocks](#corner_block). Uses [fixing blocks](#fixing_block) and [corner blocks](#corner_block).
@ -3181,26 +3185,29 @@ Uses [fixing blocks](#fixing_block) and [corner blocks](#corner_block).
| ```bbox_base_sheet(type)``` | Sheet type for the base | | ```bbox_base_sheet(type)``` | Sheet type for the base |
| ```bbox_depth(type)``` | Internal depth | | ```bbox_depth(type)``` | Internal depth |
| ```bbox_height(type)``` | Internal height | | ```bbox_height(type)``` | Internal height |
| ```bbox_name(type)``` | Optional name if there is more than one box in a project |
| ```bbox_screw(type)``` | Screw type for corner blocks | | ```bbox_screw(type)``` | Screw type for corner blocks |
| ```bbox_sheets(type)``` | Sheet type for the sides | | ```bbox_sheets(type)``` | Sheet type for the sides |
| ```bbox_skip_blocks(type)``` | List of fixing blocks to skip, used to allow a hinged panel for example |
| ```bbox_span(type)``` | Maximum span between fixing blocks | | ```bbox_span(type)``` | Maximum span between fixing blocks |
| ```bbox_top_sheet(type)``` | Sheet type for the top | | ```bbox_top_sheet(type)``` | Sheet type for the top |
| ```bbox_width(type)``` | Internal width | | ```bbox_width(type)``` | Internal width |
| ```star_washers(type)``` | Set to false to remove star washers. |
### Modules ### Modules
| Module | Description | | Module | Description |
|:--- |:--- | |:--- |:--- |
| ```_bbox_assembly(type, top = true, base = true, left = true, right = true, back = true, front = true)``` | The box assembly, wrap with a local copy without parameters | | ```_bbox_assembly(type, top = true, base = true, left = true, right = true, back = true, front = true)``` | The box assembly, wrap with a local copy without parameters |
| ```bbox_back(type)``` | Default back, can be overridden to customise | | ```bbox_back(type)``` | Default back, can be overridden to customise |
| ```bbox_back_blank(type)``` | 2D template for the back | | ```bbox_back_blank(type, sheet = false)``` | 2D template for the back |
| ```bbox_base(type)``` | Default base, can be overridden to customise | | ```bbox_base(type)``` | Default base, can be overridden to customise |
| ```bbox_base_blank(type)``` | 2D template for the base | | ```bbox_base_blank(type)``` | 2D template for the base |
| ```bbox_front(type)``` | Default front, can be overridden to customise | | ```bbox_front(type)``` | Default front, can be overridden to customise |
| ```bbox_front_blank(type)``` | 2D template for the front | | ```bbox_front_blank(type, sheet = false)``` | 2D template for the front |
| ```bbox_left(type)``` | Default left side, can be overridden to customise | | ```bbox_left(type)``` | Default left side, can be overridden to customise |
| ```bbox_left_blank(type)``` | 2D template for the left side | | ```bbox_left_blank(type, sheet = false)``` | 2D template for the left side |
| ```bbox_right(type)``` | Default right side, can be overridden to customise | | ```bbox_right(type)``` | Default right side, can be overridden to customise |
| ```bbox_right_blank(type)``` | 2D template for the right side | | ```bbox_right_blank(type, sheet = false)``` | 2D template for the right side |
| ```bbox_shelf_blank(type)``` | 2D template for a shelf | | ```bbox_shelf_blank(type)``` | 2D template for a shelf |
| ```bbox_top(type)``` | Default top, can be overridden to customise | | ```bbox_top(type)``` | Default top, can be overridden to customise |
| ```bbox_top_blank(type)``` | 2D template for the top | | ```bbox_top_blank(type)``` | 2D template for the top |