6 messages
Open this post in threaded view
|

Open this post in threaded view
|

## Re: Accumulating variable in openSCAD

 Try two passes. First generate a list of the dia and offset as pairs. Then consume the list while making the objects. dims = [ for (a=[0:20]) [1+a/10, 4+(1+a/10)*2]  ]; echo(dims); difference() {     cube([90, 30, 5]);     //     for (d = dims) {         #translate([d[1], 4, -1])             cylinder(h=7, d=d[0]);     } } On 10/22/2018 9:49 PM, Philip Jones wrote: Hi, I’m new here, so thanks for adding me to the list.   I would like some advice on how to achieve something in openSCAD programming language. I want to put a row of holes into something where each hole is larger than the last and with the holes spaced apart by the diameter of the previous hole (basically a drill size guide).   Something like: difference() {   cube([90, 30, 5]);   offset = 0;   for (a = [0: 1: 20])   {     dia = 1.0+(a/10.0);     offset = 4 + (2 * dia);     translate([offset, 4, -1])     {       cylinder(h=7, d=dia);     }   } }   This produces a row of holes of increasing size, but the increasing offset doesn’t work. I think I read that autoSCAD doesn’t have “variables” like other programming languages (clearly ‘offset’ isn’t working how I am expecting it to) but not being an expert (except perhaps in ‘C’ which I’ve used for about 30 years) I don’t really know what that means or how to write something that would work.   Any advice, or code example would be gratefully received.   PhilipJ   ```_______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org ``` _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: Accumulating variable in openSCAD

 Neon22 wrote > Try two passes. First generate a list of the dia and offset as >       pairs. >       Then consume the list while making the objects. >     dims = [ for (a=[0:20]) [1+a/10, 4+(1+a/10)*2]  ]; >       echo(dims); >       difference() { >           cube([90, 30, 5]); >           // >           for (d = dims) { >               #translate([d[1], 4, -1]) >                   cylinder(h=7, d=d[0]); >           } >       } Thanks for that, I'm always learning something :-) PhilipJ -- Sent from: http://forum.openscad.org/_______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: Accumulating variable in openSCAD

 In reply to this post by Neon22 Hi again, I tried your code suggestion and it worked as it was supposed to but it made me realize I need a more complex set of offsets. Basically the offset needs to be:      the offset of the previous element + 2 * dia of the hole. I'm not familiar with how to manipulate 'lists' so can you suggest how I could do something like:    dims[i] = dims[i-1] + 2 * dia; I only know how to show this in 'C' so it's probably nonsense in OpenSCAD language. I have looked through the online documentation but I can't find anything that specifically explains this usage of creating a list or of the for(d=dims) usage. Is this a general scripting form ? will I find it in documentation for Python or Lua ? Sorry for using up your time like this, I appreciate the help PhilipJ -- Sent from: http://forum.openscad.org/_______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: Accumulating variable in openSCAD

Open this post in threaded view
|