discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

projection

F
fractorr
Wed, May 2, 2018 5:19 PM

I was wanting to use the projection function conditionally in a module but I
get an error, is there a way to do this? This is the code I have that gets
an error

module draw_circle(param1, param2, param3, flat="no") {
if (flat == "yes") {
projection()
}

draw shape code goes here

}

If I take out the if statement like so it does what I want

module draw_circle(param1, param2, param3, flat="no") {
projection()

draw shape code goes here

}

--
Sent from: http://forum.openscad.org/

I was wanting to use the projection function conditionally in a module but I get an error, is there a way to do this? This is the code I have that gets an error module draw_circle(param1, param2, param3, flat="no") { if (flat == "yes") { projection() } draw shape code goes here } If I take out the if statement like so it does what I want module draw_circle(param1, param2, param3, flat="no") { projection() draw shape code goes here } -- Sent from: http://forum.openscad.org/
NH
nop head
Wed, May 2, 2018 5:41 PM

This works:

module draw_circle(param1, param2, param3, flat=false) {
module draw_shape() {
sphere(param1);
}

    if (flat) {
        projection()
            draw_shape();
    }
    else
        draw_shape();

}

On 2 May 2018 at 18:19, fractorr fractorr@gmail.com wrote:

I was wanting to use the projection function conditionally in a module but
I
get an error, is there a way to do this? This is the code I have that gets
an error

module draw_circle(param1, param2, param3, flat="no") {
if (flat == "yes") {
projection()
}

     draw shape code goes here

}

If I take out the if statement like so it does what I want

module draw_circle(param1, param2, param3, flat="no") {
projection()

     draw shape code goes here

}

--
Sent from: http://forum.openscad.org/


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

This works: module draw_circle(param1, param2, param3, flat=false) { module draw_shape() { sphere(param1); } if (flat) { projection() draw_shape(); } else draw_shape(); } On 2 May 2018 at 18:19, fractorr <fractorr@gmail.com> wrote: > I was wanting to use the projection function conditionally in a module but > I > get an error, is there a way to do this? This is the code I have that gets > an error > > module draw_circle(param1, param2, param3, flat="no") { > if (flat == "yes") { > projection() > } > > draw shape code goes here > } > > > > If I take out the if statement like so it does what I want > > > module draw_circle(param1, param2, param3, flat="no") { > projection() > > draw shape code goes here > } > > > > > > -- > Sent from: http://forum.openscad.org/ > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
TO
Trevor Orr
Wed, May 2, 2018 6:01 PM

Great, thanks.  That will require a little re-orgranization of my code
but it will be worth it to have the ability to do.

On 5/2/18, nop head nop.head@gmail.com wrote:

This works:

module draw_circle(param1, param2, param3, flat=false) {
module draw_shape() {
sphere(param1);
}

     if (flat) {
         projection()
             draw_shape();
     }
     else
         draw_shape();

}

On 2 May 2018 at 18:19, fractorr fractorr@gmail.com wrote:

I was wanting to use the projection function conditionally in a module
but
I
get an error, is there a way to do this? This is the code I have that
gets
an error

module draw_circle(param1, param2, param3, flat="no") {
if (flat == "yes") {
projection()
}

     draw shape code goes here

}

If I take out the if statement like so it does what I want

module draw_circle(param1, param2, param3, flat="no") {
projection()

     draw shape code goes here

}

--
Sent from: http://forum.openscad.org/


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

--
Trevor Orr
FractOrr Computer Services
fractorr.com
541-490-5697

Great, thanks. That will require a little re-orgranization of my code but it will be worth it to have the ability to do. On 5/2/18, nop head <nop.head@gmail.com> wrote: > This works: > > module draw_circle(param1, param2, param3, flat=false) { > module draw_shape() { > sphere(param1); > } > > if (flat) { > projection() > draw_shape(); > } > else > draw_shape(); > } > > > On 2 May 2018 at 18:19, fractorr <fractorr@gmail.com> wrote: > >> I was wanting to use the projection function conditionally in a module >> but >> I >> get an error, is there a way to do this? This is the code I have that >> gets >> an error >> >> module draw_circle(param1, param2, param3, flat="no") { >> if (flat == "yes") { >> projection() >> } >> >> draw shape code goes here >> } >> >> >> >> If I take out the if statement like so it does what I want >> >> >> module draw_circle(param1, param2, param3, flat="no") { >> projection() >> >> draw shape code goes here >> } >> >> >> >> >> >> -- >> Sent from: http://forum.openscad.org/ >> >> _______________________________________________ >> OpenSCAD mailing list >> Discuss@lists.openscad.org >> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >> > -- Trevor Orr FractOrr Computer Services fractorr.com 541-490-5697
JB
Jordan Brown
Thu, May 3, 2018 2:54 PM

Or something like this should work:

module conditional_project(flat) {
    if (flat == "yes") {
        projection() children();
    } else {
        children();
    }
}

module draw_circle(param1, param2, param3, flat="no") {
conditional_project(flat) {
draw shape code goes here
}
}

But I would use a boolean rather than a string for "flat".

Or something like this should work: module conditional_project(flat) {     if (flat == "yes") {         projection() children();     } else {         children();     } } module draw_circle(param1, param2, param3, flat="no") { conditional_project(flat) { draw shape code goes here } } But I would use a boolean rather than a string for "flat".