This is my first attempt at an OpenSCAD script for something functional; if anyone has suggestions for improvement they're happily accepted.

Curious Aardvark sent a script about a month ago to solve a similar problem with a cylinder: make one half of a box fit snugly into the opposite half. The cylinder function is nice in that you can specify separate diameters for the top and bottom. With the cube function, though, the most straightforward method I came up with was to iterate through a loop and make a series of very thin boxes with an incremental change to the dimensions.

This is just the half with the slope -- I'd generated the matching receptacle separately. The sides on that half don't slope.


//Rectangular Pressure Sleeve by DrUsual
mbd=50; //main box depth
mbl=90; //main box length
mbt=4; //main box wall thickness

inh=5; //height of the insert overlap

dd=.1; //difference in width and depth dimensions with each layer

ist=2; //inside sleeve thickness
isd=mbd - ist * 2 - dd; //inside sleeve starting depth
isl=mbl - ist * 2 - dd; //inside sleeve starting length
ish=1; //inside sleeve layer height

union() {
//Main box below the sleeve

difference() {
cube([mbd, mbl, 5], true);
cube([mbd-mbt*2, mbl-mbt*2, 5], true);
}

//First layer of the sleeve
translate([0, 0, 2.5])

difference(){
cube([isd, isl, ish], true);
cube([isd-ist*2, isl-ist*2, ish], true);
}

//Additional sleeve layers

for (x = [1 : 4] ) {
translate([0, 0, 2.5 + x*ish])

difference(){
cube([isd - dd*x, isl - dd*x, ish], true);
cube([isd-ist*2, isl-ist*2, ish], true);
}
}


}