discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Passing objects to modules

SH
Stephen Holt
Mon, Feb 24, 2020 1:56 AM

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 = radiuscos(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.

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.
M
MichaelAtOz
Mon, Feb 24, 2020 2:04 AM

$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/

$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/
S
steveh
Mon, Feb 24, 2020 2:34 AM

Thanks very much, brilliant !

Steve

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

Thanks very much, brilliant ! Steve -- Sent from: http://forum.openscad.org/