How to apply changes to all shapes generated in a for loop?

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

How to apply changes to all shapes generated in a for loop?

jamcultur
I have a long complicated piece of OpenSCAD code that I am trying to
simplify. The code generates shapes in a for loop, and modifies them. I
tried to use children(), but OpenSCAD unions the shapes generated in for
loops, so that didn't work. Here is a simplified example that doesn't work:

module translate_children() {
    for (i=[0:$children-1])
        translate([i*15, 0, 0])
            children(i);
}

translate_children() {
    for (j=[0:8])
        cube([10, 10, 5]);
}

I could also simplify the code if OpenSCAD allowed me to pass a reference to a
function, but that isn't supported. Does anyone have any suggestions?

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

Re: How to apply changes to all shapes generated in a for loop?

NateTG
Can you  replace cube with mycube() so that you have

module mycube(j,x,y,z) {
   foo(j) {
      cube([x,y,z]);
   }
}



--
Sent from: http://forum.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: How to apply changes to all shapes generated in a for loop?

jamcultur
NateTG wrote
> Can you  replace cube with mycube() so that you have
>
> module mycube(j,x,y,z) {
>    foo(j) {
>       cube([x,y,z]);
>    }
> }

What is foo()? When I code it as you have shown it, I get no output.



--
Sent from: http://forum.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: How to apply changes to all shapes generated in a for loop?

NateTG
I mean putting the function into the loop, rather than the loop output into
the function:


for (j=[0:8])
     mycube(j,[10, 10, 5]);

module mycube(i,d) {
   translate([i*15,0,0])
      cube(d);
}



--
Sent from: http://forum.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: How to apply changes to all shapes generated in a for loop?

jamcultur
NateTG wrote

> I mean putting the function into the loop, rather than the loop output
> into
> the function:
>
>
> for (j=[0:8])
>      mycube(j,[10, 10, 5]);
>
> module mycube(i,d) {
>    translate([i*15,0,0])
>       cube(d);
> }

That's the way it works now and is what I'm hoping to change.



--
Sent from: http://forum.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: How to apply changes to all shapes generated in a for loop?

Troberg
In reply to this post by jamcultur
> What is foo()? When I code it as you have shown it, I get no output.

foo() is a generic placeholder used in examples for "do something here". In
this case, it would do whatever your extra parameter would need to be done.



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

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