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