I often make small electrical projects and one of the silly costs is the small project boxes that house these projects, they are not cheap so I decided to write a small Openscad program to create one of any size that was necessary and that still worked no matter the dimensions.
As it happened I came across such a design that was easy to modify to suit myself.
Obviously you can’t print the lid as it appears in the picture but the “slicing” software allows you to separate it and print it beside the box at the same time.
This is the code:
//Customisable box with lid
//Variables****************
//outside dimensions
width=50;
length=100;
height=30;
//Other variables (in mm)
corner_r=5; //Radius of corners
wall_thick=4; //Box wall thickness
post_d=10; //Mounting post diameter
hole_d=3; //Screw size diameter
lid_thick=2; //Lid thickness
lid_lip=2; //Supporting lip for lid
lid_tol=.4; //Fit tolerance - so lid is not tight fit
//End Variables************
$fn=50;
//Basic Box
difference(){
hull(){
posts(
x=(width/2-corner_r),
y=(length/2-corner_r),
z=0,
h=height,
r=corner_r);
}
//Contents
hull(){
posts(
x=(width/2-corner_r-wall_thick),
y=(length/2-corner_r-wall_thick),
z=wall_thick,
h=height,
r=corner_r);
}
//Lip inside Box
hull(){
posts(
x=(width/2-corner_r-lid_lip),
y=(length/2-corner_r-lid_lip),
z=(height-lid_thick),
h=lid_thick+1,
r=corner_r);
}
}
//Support Posts
difference(){
posts(
x=(width/2-wall_thick/2-post_d/2),
y=(length/2-wall_thick/2-post_d/2),
z=wall_thick-.5,
h=height-wall_thick-lid_thick+.5,
r=post_d/2);
//Holes in posts
posts(
x=(width/2-wall_thick/2-post_d/2),
y=(length/2-wall_thick/2-post_d/2),
z=wall_thick,
h=height-wall_thick-lid_thick+.5,
r=hole_d/2);
}
//Lid
difference(){
hull(){
posts(
x=(width/2-corner_r-wall_thick/2-lid_tol),
y=(length/2-corner_r-wall_thick/2-lid_tol),
z=height-lid_thick+10,
h=lid_thick,
r=corner_r);
}
//holes in lid
posts(
x=(width/2-wall_thick/2-post_d/2),
y=(length/2-wall_thick/2-post_d/2),
z=height-lid_thick+10,
h=height-wall_thick-lid_thick+.5,
r=hole_d/2+.5);
}
//Main Construction Module
module posts(x,y,z,h,r)
{
translate([x,y,z]) {
cylinder(r=r,h=h);
}
translate([-x,y,z]) {
cylinder(r=r,h=h);
}
translate([-x,-y,z]) {
cylinder(r=r,h=h);
}
translate([x,-y,z]) {
cylinder(r=r,h=h);
}
}
For example if I wanted to add a hole for a switch it was a simple matter of adding this bit of code in the right place.
//Hole in lid for a 0.5 inch switch
translate([0,0,height+9.5,])
cylinder(h=lid_thick+1,d=12.5);
to give you this
Also if I was making a hole in the lid I would want the lid to be thicker for extra strength and that would just be a matter of increasing the variable “lid_thick” from, say 2 to 4, the change would automatically be catered for in the rest of the code as can be seen on the picture.
I have got to say how much I am enjoying using the printer and also the Openscad software, the lattr is brilliant (and free). I still forget the occasional semi colon (very important) and the “rotate” command drives me up the wall but it is a lot of fun especially on wet miserable days like today.