I'm trying to either access and assign the values assigned to coordinates through the forloop to their single variables as below, or at least be able to access the values separately in the Matrix.
for ( coordinates = [ [ 15, 15, 2],
[ 15, -15, 2],
[ -15, -15, 2],
[ -15, 15, 2] ])
{
x = coordinates[0];
y = coordinates[1];
z = coordinates[2];
translate([x+4, y, z]){
cube([x,y,z]);
}
}
First off, standard variables are set at compile-time in OpenSCAD, not run-time (official documentation stating that), so you can't assign values to them in a loop. You'll have to inline references to
coordinates
to use the values in it.The second issue is that you can't make a cube with a negative size, or so I'm guessing from the fact that I get no output from the second through fourth iterations of the loop as provided. You can wrap the values passed into cube in
abs()
calls to get the absolute value to ensure it's positive.Here's a working sample of inlining the
coordinates
variable and usingabs()
to pass positive values tocube()
: