Nabble has removed Mailing-list integration.
Posts created here DO NOT GET SENT TO THE MAILING LIST.
Mailing-list emails DO NOT GET POSTED TO THE FORUM.
So basically the Forum is now out of date, we are looking into migrating the history.

For now you should send emails, people will see them, discuss@lists.openscad.org.

Passing objects to modules

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

Passing objects to modules

steveh
Hi all,


Being new to openScad I'm exploring its methods with a view to replacing
another CAD program I have.


I have wriiten this:-

----------------------------------------------------

$fn = 50;

module RadialCopy( numCopies, radius)
{
     dtr = PI/180;
     angStep = 360/numCopies;

     for(i=[0:angStep:360])
     {
         x = radius*cos(i);
         y = radius*sin(i);

         translate([x,y,0])cylinder(5,1,true);
     }
}

// Call the RadialCopy module

RadialCopy( 6, 10);

--------------------------------------------------


which copies a cylinder <numCopies> times around a centre point.


but what if I wanted to copy another object like a sphere or a cube ? I
would have to change the RadialCopy module each time, instead I want to
keep the generality of the module, and pass the object I want to copy as
a parameter.


Can I do this ? I've read a bit about using children but didn't really
understand it or get it to work the way I wanted.


Any advice appreciated.

thanks,

Steve.



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

Re: Passing objects to modules

MichaelAtOz
Administrator
$fn = 50;

module RadialCopy( numCopies, radius)
{
     dtr = PI/180;
     angStep = 360/numCopies;

     for(i=[0:angStep:360])
     {
         x = radius*cos(i);
         y = radius*sin(i);

         translate([x,y,0]) children();
     }
}

// Call the RadialCopy module

RadialCopy( 6, 10)
  cylinder(5,1,true);

RadialCopy( 6, 15)
  cube(1);




-----
Admin - email* me if you need anything,  or if I've done something stupid...

* click on my MichaelAtOz label, there is a link to email me.

Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above.

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

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
OpenSCAD Admin - email* me if you need anything, or if I've done something stupid...
* on the Forum, click on my MichaelAtOz label, there is a link to email me.

Unless specifically shown otherwise above, my contribution is in the Public Domain;
to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work.
Obviously inclusion of works of previous authors is not included in the above.
Reply | Threaded
Open this post in threaded view
|

Re: Passing objects to modules

steveh
In reply to this post by steveh
Thanks very much, brilliant !

Steve



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

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