stl() and dxf() can now have the code to make the STL or DXF as a child.

This allows them to be replaced by the STL or DXF when making assembly views.

use_dxf() and use_stl() make use of $cwd and $target, so can be in bom.scad
and be documented.

Corrected the spelling of widget in BOM test.
This commit is contained in:
Chris Palmer 2021-02-06 15:23:10 +00:00
parent 079168142b
commit 5bac2bf46d
4 changed files with 64 additions and 40 deletions

View File

@ -6008,6 +6008,10 @@ This is to prevent the global BOM page becoming too wide in large projects by ha
The example below shows how to define a vitamin and incorporate it into an assembly with sub-assemblies and make an exploded view.
The resulting flat BOM is shown but heirachical BOMs are also generated for real projects.
If the code to make an STL or DXF is made a child of the `stl()` or `dxf()` module then the STL or DXF will be used in the assembly views generated by `views.py` instead of generating
it with code.
This can speed up the generation of the build instructions greatly but isn't compatible with STLs that include support structures.
[utils/core/bom.scad](utils/core/bom.scad) Implementation.
[tests/BOM.scad](tests/BOM.scad) Code for this example.
@ -6036,7 +6040,9 @@ The resulting flat BOM is shown but heirachical BOMs are also generated for real
| `pose_vflip(exploded = undef)` | Pose an STL or assembly for rendering to png by flipping around the X axis, `exploded = true for` just the exploded view or `false` for unexploded only. |
| `stl(name)` | Name an stl that will appear on the BOM, there needs to a module named `<name>_stl` to make it |
| `stl_colour(colour = pp1_colour, alpha = 1)` | Colour an stl where it is placed in an assembly. `alpha` can be used to make it appear transparent. |
| `vitamin(description)` | Describe a vitamin for the BOM entry and precede it with a module call that creates it, eg. "wigit(42): Type 42 widget" |
| `use_dxf(name)` | Import a DXF to make a build panel |
| `use_stl(name)` | Import an STL to make a build platter |
| `vitamin(description)` | Describe a vitamin for the BOM entry and precede it with a module call that creates it, eg. "widget(42): Widget size 42" |
![bom](tests/png/bom.png)
@ -6063,9 +6069,9 @@ The resulting flat BOM is shown but heirachical BOMs are also generated for real
### Assemblies
| Qty | Name |
| ---:|:--- |
| 1 | widget_assembly |
| 1 | widget_base_assembly |
| 1 | widget_top_assembly |
| 1 | widgit_base_assembly |
| 1 | wigdit_assembly |
<a href="#top">Top</a>

View File

@ -43,9 +43,8 @@ module widget(thickness) {
}
}
module widgit_stl() {
stl("widget");
module widget_stl() {
stl("widget")
union() {
rounded_rectangle([30, 30, 3], 2);
@ -53,9 +52,8 @@ module widgit_stl() {
}
}
module widgit_dxf() {
dxf("widget");
module widget_dxf() {
dxf("widget")
difference() {
sheet_2D(sheet, 20, 20, 1);
@ -64,10 +62,10 @@ module widgit_dxf() {
}
//! * Push the insert into the base with a soldering iron heated to 200&deg;C
module widgit_base_assembly()
assembly("widgit_base") {
module widget_base_assembly()
assembly("widget_base") {
stl_colour(pp1_colour)
widgit_stl();
widget_stl();
translate_z(height)
insert(insert);
@ -80,14 +78,14 @@ assembly("widget_top") {
widget(sheet_thickness(sheet));
render_2D_sheet(sheet) // Must be last because it is transparent
widgit_dxf();
widget_dxf();
}
//! * Screw the two assemblies together
module widgit_assembly()
assembly("wigdit") {
module widget_assembly()
assembly("widget") {
widgit_base_assembly(); // Note this is not exloded because it is sub-assembly
widget_base_assembly(); // Note this is not exloded because it is sub-assembly
translate_z(height) {
translate_z(sheet_thickness(sheet))
@ -100,7 +98,7 @@ assembly("wigdit") {
}
module boms() {
widgit_assembly();
widget_assembly();
}
boms();

View File

@ -30,6 +30,10 @@
//!
//! The example below shows how to define a vitamin and incorporate it into an assembly with sub-assemblies and make an exploded view.
//! The resulting flat BOM is shown but heirachical BOMs are also generated for real projects.
//!
//! If the code to make an STL or DXF is made a child of the `stl()` or `dxf()` module then the STL or DXF will be used in the assembly views generated by `views.py` instead of generating
//! it with code.
//! This can speed up the generation of the build instructions greatly but isn't compatible with STLs that include support structures.
//
function bom_mode(n = 1) = $_bom >= n && (is_undef($on_bom) || $on_bom); //! Current BOM mode, 0 = none, 1 = printed and routed parts and assemblies, 2 includes vitamins as well
function exploded() = is_undef($exploded_parent) ? $exploded : 0; //! Returns the value of `$exploded` if it is defined, else `0`
@ -111,19 +115,47 @@ module stl_colour(colour = pp1_colour, alpha = 1) { //! Colour an stl where it i
}
module stl(name) { //! Name an stl that will appear on the BOM, there needs to a module named `<name>_stl` to make it
if(bom_mode()) {
if(bom_mode() && is_undef($in_stl)) {
colour = is_undef($stl_colour) ? pp1_colour : $stl_colour;
echo(str("~", name, ".stl(colour='", colour, "')"));
}
if($children)
if(is_undef($pose))
let($in_stl = true)
children();
else {
path = is_undef($target) ? "/stls/" : str("/", $target, "/stls/");
import(str($cwd, path, name, ".stl"));
}
}
module dxf(name) { //! Name a dxf that will appear on the BOM, there needs to a module named `<name>_dxf` to make it
if(bom_mode()) {
if(bom_mode() && is_undef($in_dxf)) {
if(is_undef($dxf_colour))
echo(str("~", name, ".dxf"));
else
echo(str("~", name, ".dxf(colour='", $dxf_colour, "')"));
}
if($children)
if(is_undef($pose))
let($in_dfx = true)
children();
else {
path = is_undef($target) ? "/dxfs/" : str("/", $target, "/dxfs/");
import(str($cwd, path, name, ".dxf"));
}
}
module use_stl(name) { //! Import an STL to make a build platter
stl(name);
path = is_undef($target) ? "/stls/" : str("/", $target, "/stls/");
import(str($cwd, path, name, ".stl"));
}
module use_dxf(name) { //! Import a DXF to make a build panel
dxf(name);
path = is_undef($target) ? "/dxfs/" : str("/", $target, "/dxfs/");
import(str($cwd, path, name, ".dxf"));
}
function value_string(value) = is_string(value) ? str("\"", value, "\"") : str(value); //! Convert `value` to a string or quote it if it is already a string
@ -133,7 +165,7 @@ function arg(value, default, name = "") = //! Create string for arg if not def
: name ? str(", ", name, " = ", value_string(value))
: str(", ", value_string(value));
module vitamin(description) { //! Describe a vitamin for the BOM entry and precede it with a module call that creates it, eg. "wigit(42): Type 42 widget"
module vitamin(description) { //! Describe a vitamin for the BOM entry and precede it with a module call that creates it, eg. "widget(42): Widget size 42"
if(bom_mode(2))
echo(str("~", description, !is_undef($hidden) ? " - not shown" : ""));
}

View File

@ -25,15 +25,3 @@ include <../../global_defs.scad>
// Global functions and modules
//
use <global.scad>
module use_stl(name) { //! Import an STL to make a build platter
stl(name);
path = is_undef($target) ? "../stls/" : str("../", $target, "/stls/");
import(str(path, name, ".stl"));
}
module use_dxf(name) { //! Import a DXF to make a build panel
dxf(name);
path = is_undef($target) ? "../dxfs/" : str("../", $target, "/dxfs/");
import(str(path, name, ".dxf"));
}