NopSCADlib/tests/BOM.scad

108 lines
2.8 KiB
OpenSCAD
Raw Normal View History

//
// NopSCADlib Copyright Chris Palmer 2018
// nop.head@gmail.com
// hydraraptor.blogspot.com
//
// This file is part of NopSCADlib.
//
// NopSCADlib is free software: you can redistribute it and/or modify it under the terms of the
// GNU General Public License as published by the Free Software Foundation, either version 3 of
// the License, or (at your option) any later version.
//
// NopSCADlib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along with NopSCADlib.
// If not, see <https://www.gnu.org/licenses/>.
//
//
//! BOM and assembly demonstration
//
include <../core.scad>
include <../vitamins/sheets.scad>
use <../vitamins/insert.scad>
$explode = 1; // Normally set on the command line when generating assembly views with views.py
screw = M3_cap_screw;
sheet = PMMA3;
height = 10;
insert = screw_insert(screw);
washer = screw_washer(screw);
module widget(thickness) {
vitamin(str("widget(", thickness, "): Rivit like thing for ", thickness, "mm sheets"));
t = 1;
color("silver") {
cylinder(d = 3, h = thickness + 2 * eps, center = true);
for(end = [-1, 1])
translate_z(end * (thickness / 2 + t / 2 + eps))
cylinder(d = 4, h = t, center = true);
}
}
module widgit_stl() {
stl("widget");
union() {
rounded_rectangle([30, 30, 3], 2);
render() insert_boss(insert, height, 2.2);
}
}
module widgit_dxf() {
dxf("widget");
difference() {
sheet_2D(sheet, 20, 20, 1);
drill(screw_clearance_radius(screw), 0);
}
}
//! * Push the insert into the base with a soldering iron heated to 200&deg;C
module widgit_base_assembly()
assembly("widgit_base") {
color(pp1_colour)
widgit_stl();
translate_z(height)
insert(insert);
}
//! * Magically insert the widget into the acrylic sheet
module widget_top_assembly()
assembly("widget_top") {
translate([-5, 5])
widget(sheet_thickness(sheet));
render_2D_sheet(sheet) // Must be last because it is transparent
widgit_dxf();
}
//! * Screw the two assemblies together
module widgit_assembly()
assembly("wigdit") {
widgit_base_assembly(); // Note this is not exloded because it is sub-assembly
translate_z(height) {
translate_z(sheet_thickness(sheet))
screw_and_washer(screw, screw_longer_than(sheet_thickness(sheet) + 2 * washer_thickness(washer) + 3), true);
explode(5)
translate_z(sheet_thickness(sheet) / 2 + eps)
widget_top_assembly();
}
}
module boms() {
widgit_assembly();
}
boms();