calling a module "by name"?

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

calling a module "by name"?

marhar
I have a module that will instantiate several copies of an item in a grid-like array.  It's useful for printing several copies of an item.

multiple_print(3,2);

It does the obvious for loop, and incorporates the module named item().

Is there a way to pass in a module name and have it incorporate a module instantion by name?  Or a lambda-like facility or somesuch?

Context:  I have several motor mounts in different sizes, and would like to bring them into one scad session so they can be displayed next to each other.

print_several("mount1","mount2","mount3")
Reply | Threaded
Open this post in threaded view
|

Re: calling a module "by name"?

nophead
The way do do it in OpenScad is to make the module a child(). E.g.

multiple_print(3,2)
    item();

Inside multiple_print() you reference item() as child() or child(0);

You can then do
multiple_print(3,2)
    another_item();

And
print_several() {
      mount1(); mount2(); mount3();
}

You access the children with a loop for(i = [0, $children -1]) child(i);


On 12 July 2013 02:37, marhar <[hidden email]> wrote:
I have a module that will instantiate several copies of an item in a
grid-like array.  It's useful for printing several copies of an item.

multiple_print(3,2);

It does the obvious for loop, and incorporates the module named item().

Is there a way to pass in a module name and have it incorporate a module
instantion by name?  Or a lambda-like facility or somesuch?

Context:  I have several motor mounts in different sizes, and would like to
bring them into one scad session so they can be displayed next to each
other.

print_several("mount1","mount2","mount3")



--
View this message in context: http://forum.openscad.org/calling-a-module-by-name-tp5156.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
Reply | Threaded
Open this post in threaded view
|

Re: calling a module "by name"?

marhar
Thanks, this is working splendidly now!