Hi, a simple problem, but I either need more, or less coffee to solve.
In a usual cad drawing package, objects are easily duplicated by
selecting it and copying. What is the equivalent process in openscad?
I need to copy an object, and arrange them on a 3 by 4 grid. I thought a
couple of nested for loops would do that, but found I had errors wrt
undefined variables. I've gone back to basics, and thought, lets just
copy the object, and then work out the details later. I tried this -
a=1;
xw=10;
xp=xwa;
translate([xp,10,0]){
scaledcan();
}
a=2;
xp=xwa;
translate([xp,10,0]){
scaledcan();
}
expecting to get two scaledcan() objects, 10 apart in x direction. I had
warning messages
WARNING: a was assigned on line 82 but was overwritten on line 88
WARNING: xp was assigned on line 84 but was overwritten on line 90
and only one object, when i was hoping for two, spaced xw from each
other. Any suggestions appreciated.
Best wishes,
Ray
Hi!
how large is that 'scaledcan()' object?
you don't have to enclose the 'scaledcan()' call in curly brackets.
Just use:
a=1;
xw=10;
xp=xw*a;
translate([xp,10,0])
scaledcan();
Undefined variables is often caused by capitalisation, or lack of it.
Trygve
Den 30. juli 2020 kl. 13.01.05 +02.00 skrev Ray West raywest@raywest.com:
Hi, a simple problem, but I either need more, or less coffee to solve.
In a usual cad drawing package, objects are easily duplicated by selecting it and copying. What is the equivalent process in openscad?
I need to copy an object, and arrange them on a 3 by 4 grid. I thought a couple of nested for loops would do that, but found I had errors wrt undefined variables. I've gone back to basics, and thought, lets just copy the object, and then work out the details later. I tried this -
a=1;
xw=10;
xp=xwa;
translate([xp,10,0]){
scaledcan();
}
a=2;
xp=xwa;
translate([xp,10,0]){
scaledcan();
}
expecting to get two scaledcan() objects, 10 apart in x direction. I had warning messages
WARNING: a was assigned on line 82 but was overwritten on line 88
WARNING: xp was assigned on line 84 but was overwritten on line 90
and only one object, when i was hoping for two, spaced xw from each other. Any suggestions appreciated.
Best wishes,
Ray
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Variables in OpenSCAD are immutable (
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/The_OpenSCAD_Language#Variables
).
You can't reassign a value to it as you do with a and xp. Use other
names in their second appearance.
expecting to get two scaledcan() objects, 10 apart in x direction. I had
warning messages
WARNING: a was assigned on line 82 but was overwritten on line 88
WARNING: xp was assigned on line 84 but was overwritten on line 90
and only one object, when i was hoping for two, spaced xw from each
other. Any suggestions appreciated.
On 7/30/2020 4:01 AM, Ray West wrote:
In a usual cad drawing package, objects are easily duplicated by
selecting it and copying. What is the equivalent process in openscad?
Defining the object in a module and then invoking the module multiple times.
xw = 10;
for (a = [1:2]) {
xp = xw*a;
translate([xp, 10, 0])
scaledcan();
}
or, more generally:
module dup(nx=1, ny=1, nz=1, dx=100, dy=100, dz=100) {
for (xi=[0:nx-1], yi=[0:ny-1], zi=[0:nz-1]) {
translate([xi*dx, yi*dy, zi*dz])
children();
}
}
dup(nx=2, dx=10) scaledcan();
Note that this is not the same as copying and pasting. When you do a
simple copy and paste, the copy and the original and the copy are
separate; editing one does not change the other. Here you are defining
an object (perhaps parameterized) and creating it multiple times. If
you modify the definition of the object, you're changing all of the
objects that you create. (I believe some CAD programs have this
concept, but it's not a simple copy-paste.)
for (x=[0:20:60]) {
for (y=[0:20:40]) {
translate([x,y,0])
can();
}
}
module can() {
cylinder(h=30,d=15);
}
On 30 Jul 2020 at 12:01, Ray West wrote:
I need to copy an object, and arrange them on a 3 by 4 grid. I thought a
couple of nested for loops would do that, but found I had errors wrt
undefined variables. I've gone back to basics, and thought, lets just
copy the object, and then work out the details later. I tried this -
a=1;
xw=10;
xp=xwa;
translate([xp,10,0]){
scaledcan();
}
a=2;
xp=xwa;
translate([xp,10,0]){
scaledcan();
}
and only one object, when i was hoping for two, spaced xw from each
other. Any suggestions appreciated.