Is there a clean way to set up a projection(cut=var) such that var can be
set in the interface, and if it is not set, then extrude the part to some
thickness without duplicating the call inside an if/then/else?
pseudo code:
if (projection_cut) {
projection(cut = true)
part1(var1, ... );
} else {
linear_extrude(thickness2)
part1(var1, ... );
}
I've tried a number of things and get various complaints like:
projection(cut = projection_cut)
linear_extrude(thickness2)
part1(var1, ... );
and
linear_extrude(thickness2)
projection(cut = projection_cut)
part1(var1, ... );
And similar variants.
Anyway, I am hoping to clean up some code.
EBo --
I need to modify my description above (I misunderstood what the
projection(cut) was doing). Basically under normal conditions I want the
part to 3D render, but if I set a cut variable, I wanted it projected into
2D to process as a laser cut file. I was hoping there was a trick to keep
from duplicating the calls.
EBo --
On Mon, Aug 25, 2025 at 1:00 AM John David ebo.2112@gmail.com wrote:
Is there a clean way to set up a projection(cut=var) such that var can be
set in the interface, and if it is not set, then extrude the part to some
thickness without duplicating the call inside an if/then/else?
pseudo code:
if (projection_cut) {
projection(cut = true)
part1(var1, ... );
} else {
linear_extrude(thickness2)
part1(var1, ... );
}
I've tried a number of things and get various complaints like:
projection(cut = projection_cut)
linear_extrude(thickness2)
part1(var1, ... );
and
linear_extrude(thickness2)
projection(cut = projection_cut)
part1(var1, ... );
And similar variants.
Anyway, I am hoping to clean up some code.
EBo --
On 8/25/2025 7:56 AM, John David via Discuss wrote:
Basically under normal conditions I want the part to 3D render, but if
I set a cut variable, I wanted it projected into 2D to process as a
laser cut file. I was hoping there was a trick to keep from
duplicating the calls.
shouldCut = false;
module maybeCut() {
if (shouldCut) {
projection(cut=true)
children();
} else {
children();
}
}
maybeCut() sphere(r=20);
Similarly if you really meant project rather than cut.
Thank you. That worked!
On Mon, Aug 25, 2025 at 3:40 AM Jordan Brown openscad@jordan.maileater.net
wrote:
On 8/25/2025 7:56 AM, John David via Discuss wrote:
Basically under normal conditions I want the part to 3D render, but if I
set a cut variable, I wanted it projected into 2D to process as a laser cut
file. I was hoping there was a trick to keep from duplicating the calls.
shouldCut = false;
module maybeCut() {
if (shouldCut) {
projection(cut=true)
children();
} else {
children();
}
}
maybeCut() sphere(r=20);
Similarly if you really meant project rather than cut.