discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

start a module from a variabel

MH
Matthieu Hendriks
Mon, Oct 11, 2021 3:59 PM

Is it possible to execute a module depending on a variable name.
Example:

module_to_start = "create_plate"

sys(module_to_start) or &module_to_start

module create_plate () { ...}

module create_head () { ...}

Groet Matthieu



Is it possible to execute a module depending on a variable name. Example: module_to_start = "create_plate" sys(module_to_start) or &module_to_start module create_plate () { ...} module create_head () { ...} Groet Matthieu ------------------------- -------------------------
JW
Jan Wieck
Mon, Oct 11, 2021 5:34 PM

On 10/11/21 11:59 AM, Matthieu Hendriks wrote:

Is it possible to execute a module depending on a variable name. Example:

When I have "assemblies" I usually create a drop-down list and then
create modules depending on the value. Like:

part = "body"; // [body, arm, leg, head, all]

if (part == "body") { body(); }
if (part == "arm") { arm(); }
...
if (part == "all") {
body();
arm();
leg();
head();
}

That way I can select individual parts to work on, render and export for
printing, but I can also see the entire assembly together. The "all"
selection often has some rotate() and translate() for the actual parts
to put them at the right position within the assembly.

Regards, Jan

module_to_start = "create_plate"

sys(module_to_start) or &module_to_start

module create_plate () { ...}

module create_head () { ...}

Groet Matthieu



OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

--
Jan Wieck

On 10/11/21 11:59 AM, Matthieu Hendriks wrote: > Is it possible to execute a module depending on a variable name. Example: When I have "assemblies" I usually create a drop-down list and then create modules depending on the value. Like: part = "body"; // [body, arm, leg, head, all] if (part == "body") { body(); } if (part == "arm") { arm(); } ... if (part == "all") { body(); arm(); leg(); head(); } That way I can select individual parts to work on, render and export for printing, but I can also see the entire assembly together. The "all" selection often has some rotate() and translate() for the actual parts to put them at the right position within the assembly. Regards, Jan > > module_to_start = "create_plate" > > sys(module_to_start) or &module_to_start > > module create_plate () { ...} > > module create_head () { ...} > > > > Groet Matthieu > ------------------------------------------------------------------------ > ------------------------------------------------------------------------ > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org > -- Jan Wieck
MH
Matthieu Hendriks
Mon, Oct 11, 2021 5:44 PM

Yes I do the same, it's still a workaround for the extra coding effort
:)

Groet Matthieu

Jan Wieck schreef op 2021-10-11 19:34:

On 10/11/21 11:59 AM, Matthieu Hendriks wrote:

Is it possible to execute a module depending on a variable name.
Example:

When I have "assemblies" I usually create a drop-down list and then
create modules depending on the value. Like:

part = "body"; // [body, arm, leg, head, all]

if (part == "body") { body(); }
if (part == "arm") { arm(); }
...
if (part == "all") {
body();
arm();
leg();
head();
}

That way I can select individual parts to work on, render and export
for printing, but I can also see the entire assembly together. The
"all" selection often has some rotate() and translate() for the actual
parts to put them at the right position within the assembly.

Regards, Jan

module_to_start = "create_plate"

sys(module_to_start) or &module_to_start

module create_plate () { ...}

module create_head () { ...}

Groet Matthieu



OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

Yes I do the same, it's still a workaround for the extra coding effort :) Groet Matthieu Jan Wieck schreef op 2021-10-11 19:34: > On 10/11/21 11:59 AM, Matthieu Hendriks wrote: > >> Is it possible to execute a module depending on a variable name. >> Example: > > When I have "assemblies" I usually create a drop-down list and then > create modules depending on the value. Like: > > part = "body"; // [body, arm, leg, head, all] > > if (part == "body") { body(); } > if (part == "arm") { arm(); } > ... > if (part == "all") { > body(); > arm(); > leg(); > head(); > } > > That way I can select individual parts to work on, render and export > for printing, but I can also see the entire assembly together. The > "all" selection often has some rotate() and translate() for the actual > parts to put them at the right position within the assembly. > > Regards, Jan > >> module_to_start = "create_plate" >> >> sys(module_to_start) or &module_to_start >> >> module create_plate () { ...} >> >> module create_head () { ...} >> >> Groet Matthieu >> ------------------------------------------------------------------------ >> ------------------------------------------------------------------------ >> >> _______________________________________________ >> OpenSCAD mailing list >> To unsubscribe send an email to discuss-leave@lists.openscad.org
JB
Jordan Brown
Mon, Oct 11, 2021 10:01 PM

On 10/11/2021 8:59 AM, Matthieu Hendriks wrote:

Is it possible to execute a module depending on a variable name. Example:

module_to_start = "create_plate"

sys(module_to_start) or &module_to_start 

module create_plate () { ...}

module create_head () { ...}

No.  "if" chains, or the equivalent, are the only option.

Note that "or the equivalent" can be at least somewhat OK.

selected = "create_plate";

item("create_plate") create_plate();
item("create_head") create_head();

module create_plate() {
    ...
}

module create_head() {
    ...
}

...

module item(name) {
    if (name == selected) {
        children();
    }
}

I use a more elaborate variation on this pattern to allow manual
selection (notably via the customizer) and to drive an automated
"generate PNGs and STLs for all of the models in this file" mechanism. 
I can supply that if you're interested.

On 10/11/2021 8:59 AM, Matthieu Hendriks wrote: > > Is it possible to execute a module depending on a variable name. Example: > > module_to_start = "create_plate" > > sys(module_to_start) or &module_to_start  > > module create_plate () { ...} > > module create_head () { ...} > No.  "if" chains, or the equivalent, are the only option. Note that "or the equivalent" can be at least somewhat OK. selected = "create_plate"; item("create_plate") create_plate(); item("create_head") create_head(); module create_plate() { ... } module create_head() { ... } ... module item(name) { if (name == selected) { children(); } } I use a more elaborate variation on this pattern to allow manual selection (notably via the customizer) and to drive an automated "generate PNGs and STLs for all of the models in this file" mechanism.  I can supply that if you're interested.
NH
nop head
Mon, Oct 11, 2021 11:04 PM

Yes I use a similar pattern to place components on a PCB since they are all
drawn by different modules and the PCB has a list of their names and
positions. Would be nice to have module literals but that would mix up
expressions and modules somewhat.

On Mon, 11 Oct 2021 at 23:02, Jordan Brown openscad@jordan.maileater.net
wrote:

On 10/11/2021 8:59 AM, Matthieu Hendriks wrote:

Is it possible to execute a module depending on a variable name. Example:

module_to_start = "create_plate"

sys(module_to_start) or &module_to_start

module create_plate () { ...}

module create_head () { ...}

No.  "if" chains, or the equivalent, are the only option.

Note that "or the equivalent" can be at least somewhat OK.

selected = "create_plate";

item("create_plate") create_plate();
item("create_head") create_head();

module create_plate() {
...
}

module create_head() {
...
}

...

module item(name) {
if (name == selected) {
children();
}
}

I use a more elaborate variation on this pattern to allow manual selection
(notably via the customizer) and to drive an automated "generate PNGs and
STLs for all of the models in this file" mechanism.  I can supply that if
you're interested.


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

Yes I use a similar pattern to place components on a PCB since they are all drawn by different modules and the PCB has a list of their names and positions. Would be nice to have module literals but that would mix up expressions and modules somewhat. On Mon, 11 Oct 2021 at 23:02, Jordan Brown <openscad@jordan.maileater.net> wrote: > On 10/11/2021 8:59 AM, Matthieu Hendriks wrote: > > Is it possible to execute a module depending on a variable name. Example: > > module_to_start = "create_plate" > > sys(module_to_start) or &module_to_start > > module create_plate () { ...} > > module create_head () { ...} > > > No. "if" chains, or the equivalent, are the only option. > > Note that "or the equivalent" can be at least somewhat OK. > > selected = "create_plate"; > > item("create_plate") create_plate(); > item("create_head") create_head(); > > module create_plate() { > ... > } > > module create_head() { > ... > } > > ... > > module item(name) { > if (name == selected) { > children(); > } > } > > I use a more elaborate variation on this pattern to allow manual selection > (notably via the customizer) and to drive an automated "generate PNGs and > STLs for all of the models in this file" mechanism. I can supply that if > you're interested. > > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
MH
Matthieu Hendriks
Tue, Oct 12, 2021 5:49 AM

Thanks for helping.

So the short answer is : No, it is not possible. :)

So I wrote a linux bash script to extract the module names, create an
include file with:

if(run == "moduleX") moduleX();

if(run == "moduleY") moduleY();

and include/replace this text in the original scad file.

Groet Matthieu



nop head schreef op 2021-10-12 01:04:

Yes I use a similar pattern to place components on a PCB since they are
all drawn by different modules and the PCB has a list of their names
and positions. Would be nice to have module literals but that would mix
up expressions and modules somewhat.

On Mon, 11 Oct 2021 at 23:02, Jordan Brown
openscad@jordan.maileater.net wrote:

On 10/11/2021 8:59 AM, Matthieu Hendriks wrote:

Is it possible to execute a module depending on a variable name.
Example:

module_to_start = "create_plate"

sys(module_to_start) or &module_to_start

module create_plate () { ...}

module create_head () { ...}
No.  "if" chains, or the equivalent, are the only option.

Note that "or the equivalent" can be at least somewhat OK.

selected = "create_plate";

item("create_plate") create_plate();
item("create_head") create_head();

module create_plate() {
...
}

module create_head() {
...
}

...

module item(name) {
if (name == selected) {
children();
}
}

I use a more elaborate variation on this pattern to allow manual
selection (notably via the customizer) and to drive an automated
"generate PNGs and STLs for all of the models in this file" mechanism.
I can supply that if you're interested.


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

Thanks for helping. So the short answer is : No, it is not possible. :) So I wrote a linux bash script to extract the module names, create an include file with: if(run == "moduleX") moduleX(); if(run == "moduleY") moduleY(); and include/replace this text in the original scad file. Groet Matthieu ------------------------- ------------------------- nop head schreef op 2021-10-12 01:04: > Yes I use a similar pattern to place components on a PCB since they are > all drawn by different modules and the PCB has a list of their names > and positions. Would be nice to have module literals but that would mix > up expressions and modules somewhat. > > On Mon, 11 Oct 2021 at 23:02, Jordan Brown > <openscad@jordan.maileater.net> wrote: > > On 10/11/2021 8:59 AM, Matthieu Hendriks wrote: > > Is it possible to execute a module depending on a variable name. > Example: > > module_to_start = "create_plate" > > sys(module_to_start) or &module_to_start > > module create_plate () { ...} > > module create_head () { ...} > No. "if" chains, or the equivalent, are the only option. > > Note that "or the equivalent" can be at least somewhat OK. > > selected = "create_plate"; > > item("create_plate") create_plate(); > item("create_head") create_head(); > > module create_plate() { > ... > } > > module create_head() { > ... > } > > ... > > module item(name) { > if (name == selected) { > children(); > } > } > > I use a more elaborate variation on this pattern to allow manual > selection (notably via the customizer) and to drive an automated > "generate PNGs and STLs for all of the models in this file" mechanism. > I can supply that if you're interested. > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org _______________________________________________ OpenSCAD mailing list To unsubscribe send an email to discuss-leave@lists.openscad.org
PC
Patrick Callahan
Fri, Oct 15, 2021 4:24 PM

I’m interested in a technique to create multiple output files
automatically. Let’s discuss the approach and any code you have that does
this.

Discord maybe?

On Mon, Oct 11, 2021 at 7:05 PM nop head nop.head@gmail.com wrote:

Yes I use a similar pattern to place components on a PCB since they are
all drawn by different modules and the PCB has a list of their names and
positions. Would be nice to have module literals but that would mix up
expressions and modules somewhat.

On Mon, 11 Oct 2021 at 23:02, Jordan Brown openscad@jordan.maileater.net
wrote:

On 10/11/2021 8:59 AM, Matthieu Hendriks wrote:

Is it possible to execute a module depending on a variable name. Example:

module_to_start = "create_plate"

sys(module_to_start) or &module_to_start

module create_plate () { ...}

module create_head () { ...}

No.  "if" chains, or the equivalent, are the only option.

Note that "or the equivalent" can be at least somewhat OK.

selected = "create_plate";

item("create_plate") create_plate();
item("create_head") create_head();

module create_plate() {
...n your
}

module create_head() {
...
}

...

module item(name) {
if (name == selected) {
children();
}
}

I use a more elaborate variation on this pattern to allow manual
selection (notably via the customizer) and to drive an automated "generate
PNGs and STLs for all of the models in this file" mechanism.  I can supply
that if you're interested.


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

I’m interested in a technique to create multiple output files automatically. Let’s discuss the approach and any code you have that does this. Discord maybe? On Mon, Oct 11, 2021 at 7:05 PM nop head <nop.head@gmail.com> wrote: > Yes I use a similar pattern to place components on a PCB since they are > all drawn by different modules and the PCB has a list of their names and > positions. Would be nice to have module literals but that would mix up > expressions and modules somewhat. > > On Mon, 11 Oct 2021 at 23:02, Jordan Brown <openscad@jordan.maileater.net> > wrote: > >> On 10/11/2021 8:59 AM, Matthieu Hendriks wrote: >> >> Is it possible to execute a module depending on a variable name. Example: >> >> module_to_start = "create_plate" >> >> sys(module_to_start) or &module_to_start >> >> module create_plate () { ...} >> >> module create_head () { ...} >> >> >> No. "if" chains, or the equivalent, are the only option. >> >> Note that "or the equivalent" can be at least somewhat OK. >> >> selected = "create_plate"; >> >> item("create_plate") create_plate(); >> item("create_head") create_head(); >> >> module create_plate() { >> ...n your >> } >> >> module create_head() { >> ... >> } >> >> ... >> >> module item(name) { >> if (name == selected) { >> children(); >> } >> } >> >> I use a more elaborate variation on this pattern to allow manual >> selection (notably via the customizer) and to drive an automated "generate >> PNGs and STLs for all of the models in this file" mechanism. I can supply >> that if you're interested. >> >> >> _______________________________________________ >> OpenSCAD mailing list >> To unsubscribe send an email to discuss-leave@lists.openscad.org >> > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
NH
nop head
Fri, Oct 15, 2021 5:38 PM

My library NopSCADlib allows STLs to be created automatically using some
Python scripts.

A module that creates an STL has to have a name suffixed by _stl and call
the library module st() with its own name. E.g.

module perf_spacer_stl()
stl("perf_spacer")
difference() {
r = corrected_radius(screw_radius(perf_screw));
h = perf_gap;
cylinder(r = r + 1.7, h = h);

        poly_cylinder(r = r, h = h, center = false, twist = 2);
    }

Then when it is called to make part of an assembly it will be added to the
bill of materials and running stls.py will create all the STLs for the
project. It also makes assembly instructions like this:

[image: image.png]

On Fri, 15 Oct 2021 at 17:24, Patrick Callahan pat.callahan1@gmail.com
wrote:

I’m interested in a technique to create multiple output files
automatically. Let’s discuss the approach and any code you have that does
this.

Discord maybe?

On Mon, Oct 11, 2021 at 7:05 PM nop head nop.head@gmail.com wrote:

Yes I use a similar pattern to place components on a PCB since they are
all drawn by different modules and the PCB has a list of their names and
positions. Would be nice to have module literals but that would mix up
expressions and modules somewhat.

On Mon, 11 Oct 2021 at 23:02, Jordan Brown openscad@jordan.maileater.net
wrote:

On 10/11/2021 8:59 AM, Matthieu Hendriks wrote:

Is it possible to execute a module depending on a variable name. Example:

module_to_start = "create_plate"

sys(module_to_start) or &module_to_start

module create_plate () { ...}

module create_head () { ...}

No.  "if" chains, or the equivalent, are the only option.

Note that "or the equivalent" can be at least somewhat OK.

selected = "create_plate";

item("create_plate") create_plate();
item("create_head") create_head();

module create_plate() {
...n your
}

module create_head() {
...
}

...

module item(name) {
if (name == selected) {
children();
}
}

I use a more elaborate variation on this pattern to allow manual
selection (notably via the customizer) and to drive an automated "generate
PNGs and STLs for all of the models in this file" mechanism.  I can supply
that if you're interested.


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

My library NopSCADlib allows STLs to be created automatically using some Python scripts. A module that creates an STL has to have a name suffixed by _stl and call the library module st() with its own name. E.g. module perf_spacer_stl() stl("perf_spacer") difference() { r = corrected_radius(screw_radius(perf_screw)); h = perf_gap; cylinder(r = r + 1.7, h = h); poly_cylinder(r = r, h = h, center = false, twist = 2); } Then when it is called to make part of an assembly it will be added to the bill of materials and running stls.py will create all the STLs for the project. It also makes assembly instructions like this: [image: image.png] On Fri, 15 Oct 2021 at 17:24, Patrick Callahan <pat.callahan1@gmail.com> wrote: > I’m interested in a technique to create multiple output files > automatically. Let’s discuss the approach and any code you have that does > this. > > Discord maybe? > > > On Mon, Oct 11, 2021 at 7:05 PM nop head <nop.head@gmail.com> wrote: > >> Yes I use a similar pattern to place components on a PCB since they are >> all drawn by different modules and the PCB has a list of their names and >> positions. Would be nice to have module literals but that would mix up >> expressions and modules somewhat. >> >> On Mon, 11 Oct 2021 at 23:02, Jordan Brown <openscad@jordan.maileater.net> >> wrote: >> >>> On 10/11/2021 8:59 AM, Matthieu Hendriks wrote: >>> >>> Is it possible to execute a module depending on a variable name. Example: >>> >>> module_to_start = "create_plate" >>> >>> sys(module_to_start) or &module_to_start >>> >>> module create_plate () { ...} >>> >>> module create_head () { ...} >>> >>> >>> No. "if" chains, or the equivalent, are the only option. >>> >>> Note that "or the equivalent" can be at least somewhat OK. >>> >>> selected = "create_plate"; >>> >>> item("create_plate") create_plate(); >>> item("create_head") create_head(); >>> >>> module create_plate() { >>> ...n your >>> } >>> >>> module create_head() { >>> ... >>> } >>> >>> ... >>> >>> module item(name) { >>> if (name == selected) { >>> children(); >>> } >>> } >>> >>> I use a more elaborate variation on this pattern to allow manual >>> selection (notably via the customizer) and to drive an automated "generate >>> PNGs and STLs for all of the models in this file" mechanism. I can supply >>> that if you're interested. >>> >>> >>> _______________________________________________ >>> OpenSCAD mailing list >>> To unsubscribe send an email to discuss-leave@lists.openscad.org >>> >> _______________________________________________ >> OpenSCAD mailing list >> To unsubscribe send an email to discuss-leave@lists.openscad.org >> > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
JB
Jordan Brown
Fri, Oct 15, 2021 5:40 PM

On 10/15/2021 9:24 AM, Patrick Callahan wrote:

I’m interested in a technique to create multiple output files
automatically. Let’s discuss the approach and any code you have that
does this.

I expect that nophead's scheme is more mature than mine, but here's what
I use.

I created it originally to automate creation of 100+ STLs and PNGs for
the Thingiverse publication of my house model
https://www.thingiverse.com/thing:4264614.  I later realized that it
played well with the customizer, and so I use it a lot in that way too.

Here's an example of how it's used.  I have a file for each room in the
house, and each file has the models for the furniture in that room.

// Breakfast Room Furniture
include <lib.scad>
use <furniture-lib.scad>
use <justify.scad>
use <selection.scad>

// Animation assembles and disassembles the curio cabinet.
// You can also set $t to 0 for assembled,
// 0.5 as as-printed.

// Which item to render?
$content_selected = "all"; // [ all, table, cubbies, chair, nightstand, canbox, cabinet, curio, curio_shelves, curio_body, curio_doors ]

contents() {
    item("table", distance=150) slantlegtable(w=31.5*inch, d=23.5*inch, h=25.5*inch, leg=25*inch);
    item("cubbies") rotate(180) cubbies(w=12*inch, h=31.5*inch, d=12*inch, vdivs=[13.5*inch, 17.5*inch, 21*inch, 25*inch]);
    item("chair") rotate(180) chair(w=17.5*inch, h=38*inch, d=20.5*inch, seat_h=18*inch, tilt=3, leg_type="square", leg=1.5*inch, seat_t=4.5*inch, back_t = 3*inch, upholstery="darkgray", legs="sandybrown");
    item("nightstand") brk_nightstand();
    item("canbox") canbox();
    item("cabinet", distance=150) rotate(180) part_round_cabinet();
    item("curio") curio();
    item("curio_shelves", png=false) curio($t=0.5,$part="shelves");
    item("curio_body", png=false) curio($t=0.5,$part="body");
    item("curio_doors", png=false) curio($t=0.5,$part="doors");
}

[ ... actual models ... ]

Interactively, by default it renders all of the models, spread in a
grid, but you can use the customizer to select which model to render.

For batch operation, rendereach.sh runs each SCAD file to get a list of
the items to generate (and, for PNG, camera positioning), and then
generates each of them.

The "ifpart" and "ifvariation" stuff is kind of orthogonal.  It's
intended to allow plucking out individual parts of a model, or to swap
out pieces with different variations.  I can supply some examples if
need be.

On 10/15/2021 9:24 AM, Patrick Callahan wrote: > I’m interested in a technique to create multiple output files > automatically. Let’s discuss the approach and any code you have that > does this. I expect that nophead's scheme is more mature than mine, but here's what I use. I created it originally to automate creation of 100+ STLs and PNGs for the Thingiverse publication of my house model <https://www.thingiverse.com/thing:4264614>.  I later realized that it played well with the customizer, and so I use it a lot in that way too. Here's an example of how it's used.  I have a file for each room in the house, and each file has the models for the furniture in that room. // Breakfast Room Furniture include <lib.scad> use <furniture-lib.scad> use <justify.scad> use <selection.scad> // Animation assembles and disassembles the curio cabinet. // You can also set $t to 0 for assembled, // 0.5 as as-printed. // Which item to render? $content_selected = "all"; // [ all, table, cubbies, chair, nightstand, canbox, cabinet, curio, curio_shelves, curio_body, curio_doors ] contents() { item("table", distance=150) slantlegtable(w=31.5*inch, d=23.5*inch, h=25.5*inch, leg=25*inch); item("cubbies") rotate(180) cubbies(w=12*inch, h=31.5*inch, d=12*inch, vdivs=[13.5*inch, 17.5*inch, 21*inch, 25*inch]); item("chair") rotate(180) chair(w=17.5*inch, h=38*inch, d=20.5*inch, seat_h=18*inch, tilt=3, leg_type="square", leg=1.5*inch, seat_t=4.5*inch, back_t = 3*inch, upholstery="darkgray", legs="sandybrown"); item("nightstand") brk_nightstand(); item("canbox") canbox(); item("cabinet", distance=150) rotate(180) part_round_cabinet(); item("curio") curio(); item("curio_shelves", png=false) curio($t=0.5,$part="shelves"); item("curio_body", png=false) curio($t=0.5,$part="body"); item("curio_doors", png=false) curio($t=0.5,$part="doors"); } [ ... actual models ... ] Interactively, by default it renders all of the models, spread in a grid, but you can use the customizer to select which model to render. For batch operation, rendereach.sh runs each SCAD file to get a list of the items to generate (and, for PNG, camera positioning), and then generates each of them. The "ifpart" and "ifvariation" stuff is kind of orthogonal.  It's intended to allow plucking out individual parts of a model, or to swap out pieces with different variations.  I can supply some examples if need be.
JW
Jan Wieck
Fri, Oct 15, 2021 5:54 PM

On 10/15/21 12:24 PM, Patrick Callahan wrote:

I’m interested in a technique to create multiple output files
automatically. Let’s discuss the approach and any code you have that
does this.

It works pretty straight forward using the CLI in a batch/shell script
or with a Makefile. The Makefile approach offers to only render those
output files that would change based on the modified source (.scad,
.json and other) files.

This requires to organize the work a bit and have the customizable and
global variables in a main source and an include file for each module
that defines a part of the overall project. There can be additional
files shared by parts.

As an example I will use a configurable toolbox I am working on. The
boxes would hold things like socket wrench sets or impact driver bits. A
box type becomes a named configurator parameter set. The parameter set
controls the dimensions of the box, number of hinges and the artwork on
top. A drop down string variable controls which part is to be rendered
and the toplevel .scad file makes that happen with code like

 if (part == "bottom") ToolBoxBottom();
 if (part == "top") ToolBoxTop();

The Makefile defines the dependencies and the commands to run. So if I
only modify the source code for ToolBoxBottom, it will only create a new
bottom.stl file. If I modify the toplevel ToolBox.scad file, it will
recreate all stl files. The command for (re)creating the needed stl
files for my DEMO box (attached) is

 DESIGN=DEMO make

I would need to do some code cleanup before sharing the source code.

--
Jan Wieck

On 10/15/21 12:24 PM, Patrick Callahan wrote: > I’m interested in a technique to create multiple output files > automatically. Let’s discuss the approach and any code you have that > does this. It works pretty straight forward using the CLI in a batch/shell script or with a Makefile. The Makefile approach offers to only render those output files that would change based on the modified source (.scad, .json and other) files. This requires to organize the work a bit and have the customizable and global variables in a main source and an include file for each module that defines a part of the overall project. There can be additional files shared by parts. As an example I will use a configurable toolbox I am working on. The boxes would hold things like socket wrench sets or impact driver bits. A box type becomes a named configurator parameter set. The parameter set controls the dimensions of the box, number of hinges and the artwork on top. A drop down string variable controls which part is to be rendered and the toplevel .scad file makes that happen with code like if (part == "bottom") ToolBoxBottom(); if (part == "top") ToolBoxTop(); The Makefile defines the dependencies and the commands to run. So if I only modify the source code for ToolBoxBottom, it will only create a new bottom.stl file. If I modify the toplevel ToolBox.scad file, it will recreate all stl files. The command for (re)creating the needed stl files for my DEMO box (attached) is DESIGN=DEMO make I would need to do some code cleanup before sharing the source code. -- Jan Wieck