Calling a different module using a string?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Calling a different module using a string?

alexgibson
Hi there,

I need to make some things from many layers of acrylic.  I want to be able to neatly 3 D render as I go.

I will make each layer as its own module.  There will be some copy/paste.

I wonder if I can automate calling the modules using a string somehow?

This was my optimistic attempt which failed...


module layer_1()
{
difference()
{
circle(outer_diameter/2);
circle(outer_diameter/2-wall_thickness);
}
}
module 3d_render()
{
for (i=[0:10])
translate([0,0,i*acrylic_thickness+i*explode_by_mm])
linear_extrude(acrylic_thickness)
{
str("layer_",i,"();");
}
}

3d_render();


Thanks!

Alex

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Calling a different module using a string?

alexgibson
...is there maybe a way I could store the module names in an array, and recall them using string?



On 1 November 2017 at 13:27, Alex Gibson <[hidden email]> wrote:
Hi there,

I need to make some things from many layers of acrylic.  I want to be able to neatly 3 D render as I go.

I will make each layer as its own module.  There will be some copy/paste.

I wonder if I can automate calling the modules using a string somehow?

This was my optimistic attempt which failed...


module layer_1()
{
difference()
{
circle(outer_diameter/2);
circle(outer_diameter/2-wall_thickness);
}
}
module 3d_render()
{
for (i=[0:10])
translate([0,0,i*acrylic_thickness+i*explode_by_mm])
linear_extrude(acrylic_thickness)
{
str("layer_",i,"();");
}
}

3d_render();


Thanks!

Alex


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Calling a different module using a string?

doug.moen
In reply to this post by alexgibson
Something like this should be possible:

3d_render() {
   // layer 1
   difference() { circle(outer_diameter/2); circle(outer_diameter/2-wall_thickness); }
   // layer 2
   ...
}

module 3d_render() {
   for (i=[0:10])
      translate(...i...) linear_extrude(...) children(i);
}

On 1 November 2017 at 09:27, Alex Gibson <[hidden email]> wrote:
Hi there,

I need to make some things from many layers of acrylic.  I want to be able to neatly 3 D render as I go.

I will make each layer as its own module.  There will be some copy/paste.

I wonder if I can automate calling the modules using a string somehow?

This was my optimistic attempt which failed...


module layer_1()
{
difference()
{
circle(outer_diameter/2);
circle(outer_diameter/2-wall_thickness);
}
}
module 3d_render()
{
for (i=[0:10])
translate([0,0,i*acrylic_thickness+i*explode_by_mm])
linear_extrude(acrylic_thickness)
{
str("layer_",i,"();");
}
}

3d_render();


Thanks!

Alex

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org



_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Calling a different module using a string?

jdawgaz
use solidpython or rubyscad.

you can do a lot of things there that you just cannot do in openscad itself.
and once you have created what you want, then do a render to a file.



--
Extra Ham Operator: K7AZJ
Registered Linux User: 275424
Raspberry Pi and Openscad developer

The most exciting phrase to hear in science - the one that heralds new discoveries - is not "Eureka!" but "That's funny...".
- Isaac. Asimov


On Wed, Nov 1, 2017 at 6:40 AM, doug moen <[hidden email]> wrote:
Something like this should be possible:

3d_render() {
   // layer 1
   difference() { circle(outer_diameter/2); circle(outer_diameter/2-wall_thickness); }
   // layer 2
   ...
}

module 3d_render() {
   for (i=[0:10])
      translate(...i...) linear_extrude(...) children(i);
}

On 1 November 2017 at 09:27, Alex Gibson <[hidden email]> wrote:
Hi there,

I need to make some things from many layers of acrylic.  I want to be able to neatly 3 D render as I go.

I will make each layer as its own module.  There will be some copy/paste.

I wonder if I can automate calling the modules using a string somehow?

This was my optimistic attempt which failed...


module layer_1()
{
difference()
{
circle(outer_diameter/2);
circle(outer_diameter/2-wall_thickness);
}
}
module 3d_render()
{
for (i=[0:10])
translate([0,0,i*acrylic_thickness+i*explode_by_mm])
linear_extrude(acrylic_thickness)
{
str("layer_",i,"();");
}
}

3d_render();


Thanks!

Alex

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org



_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org



_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Calling a different module using a string?

Troberg
In reply to this post by alexgibson
I do something similar when doing step by step building instructions.

Basically, I have a main drawing module, which looks like this:

module drawsteps(){

    if(currentstep==1){

    }
    if(currentstep>=1){

    }

    if(currentstep==2){

    }
    if(currentstep>=2){

    }

}

Then, I put all the drawing in separate modules, and call them from this
module. The reason I have == and >= is that I often have stuff that will
only be that way for a single frame (such as screws being shown not screwed
in fully), and then I use >= for the stuff that should remain in the
following frames.



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

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org