83 lines
2.6 KiB
OpenSCAD
83 lines
2.6 KiB
OpenSCAD
|
/**
|
||
|
* Model that draws a box that can have screws and slots and that can be used as a negative on another box and obtain the difference.
|
||
|
* can be used as a negative on another box and obtain the difference.
|
||
|
*
|
||
|
* @author Joaquín Fernández
|
||
|
* @url https://gitlab.com/joaquinfq/openscad/blob/master/Modules/Models/box.scad
|
||
|
* @license CC-BY-NC-4.0
|
||
|
*
|
||
|
* @ @param {Float} width Width of the model to generate.
|
||
|
* @ @param {Float} height Height of the model to generate.
|
||
|
* @param {Float} length Length of the model to be generated.
|
||
|
* @param {Float} thickness Thickness of the block where the model will be inserted.
|
||
|
* @param {Float} screw Diameter of the screw to be used.
|
||
|
* @param {Float} slot Length of the slot where the screws will be inserted.
|
||
|
* @param {Float} tolerance Value to be used to adjust the standard dimensions.
|
||
|
* @param {Float[]} side Coordinates of the side holes.
|
||
|
* @param {Float[]} bottom Coordinates of the bottom holes.
|
||
|
*/
|
||
|
module modelBox(width, height, length, thickness, screw = 0, slot = 0, side = [], bottom = [])
|
||
|
{
|
||
|
cube([ width, height, length ]);
|
||
|
// Side holes
|
||
|
for (_side = side)
|
||
|
{
|
||
|
if (slot)
|
||
|
{
|
||
|
hull()
|
||
|
{
|
||
|
for (_n = [ - slot / 2, slot / 2 ])
|
||
|
{
|
||
|
translate([ width / 2, _side[0], _side[1] + _n ])
|
||
|
{
|
||
|
rotate([ 0, 90, 0 ])
|
||
|
{
|
||
|
cylinder(d = screw, h = width + thickness * 2, center = true);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
translate([ width / 2, _side[0], _side[1] ])
|
||
|
{
|
||
|
rotate([ 0, 90, 0 ])
|
||
|
{
|
||
|
cylinder(d = screw, h = width + thickness * 2, center = true);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
// Bottom holes
|
||
|
for (_bottom = bottom)
|
||
|
{
|
||
|
if (slot)
|
||
|
{
|
||
|
hull()
|
||
|
{
|
||
|
for (_n = [ - slot / 2, slot / 2 ])
|
||
|
{
|
||
|
translate([ width - _bottom[0], 0, _bottom[1] + _n ])
|
||
|
{
|
||
|
rotate([ 90, 0, 0 ])
|
||
|
{
|
||
|
cylinder(d = screw, h = thickness);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
translate([ width - _bottom[0], 0, _bottom[1] ])
|
||
|
{
|
||
|
rotate([ 90, 0, 0 ])
|
||
|
{
|
||
|
cylinder(d = screw, h = thickness);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|