What is the proper way to work with arrays that have been generated with a for loop and push?
Excuse if my terminology is not correct. I'm fairly new to openjscad and js as a whole.
In essence I have an array of positions and want to punch holes in a plate at those positions.
I am trying with the following:
function pcb () {
pcb_width = 25;
pcb_height = 3;
pcb_thickness = 50;
pcb_dimmensions = [(pcb_width), (pcb_thickness), (pcb_height)];
return cube(pcb_dimmensions);
}
function holes1 () {
var array = [];
array.push(translate([10,10,0],
cylinder({h: 20})));
array.push(translate([5,10,0],
cylinder({h: 20})));
return array;
}
function holes2 () {
var holes = [];
var positions = [
[4, 12, -1],
[8, 12, -1],
[8, 18, -1],
[12, 18, -1],
];
for (i=0; i <= positions.length; i++) {
holes.push(translate(positions[i],
cylinder({h: 10})))
}
return holes
}
function main () {
//return holes2 ();
//why does return [pcb()] work but not return [holes1(), or holes2()] ?
//return [pcb(),holes1()] //does not work
//return difference (pcb(),holes1()); // does not works
return union (pcb(),holes1()); //works
//return union (pcb(),holes2()); //does not work
}
Questions:
- Why can I not return an array consisting of the pcb and the holes-array (cylinders)? Is nesting a problem here?
- Union of pcb() and holes1() works, but not if holes2() is used. The function which includes a for loop.
- Difference of pcb() and holes() works for neither.
As a side note, I am assuming the community hangs here and not on IRC or such?
Looking for a place to quickly solve some doubts to help me get on my feet.