[OpenSCAD] What's the best way to accomplish splitting these elements?

guaranteed_interwoven kerryhall at gmail.com
Mon Jul 8 03:00:02 EDT 2019

My apologies, one last question here.

I'm trying to do one last generifying step, to extend to an arbitrary number
of objects.

$fn = 20;

module gen_node(coords, d, h)
  cylinder(d1=d, d2=0, h=h);
module cutCyl()
        for(i=[1:1:$children-1]) children(i);

data = [
  [[4, 5, 0], 10, 10],
  [[0, 0, 0], 10, 20],
  [[-5, 3, 0], 15, 10],
  [[-2, 6, 0], 15, 7],

/* Does not work:
  for (i = [0: len(data)])
    gen_node(data[i][0], data[i][1], data[i][2], data[i][3]);

// Does work
  gen_node(data[0][0], data[0][1], data[0][2], data[0][3]);
  gen_node(data[1][0], data[1][1], data[1][2], data[1][3]);
  gen_node(data[2][0], data[2][1], data[2][2], data[2][3]);
  gen_node(data[3][0], data[3][1], data[3][2], data[3][3]);

I did notice that the delta doesn't work for certain shapes. The delta is a
good idea I think to guarantee that the pieces fit together once printed.
What I can do is that the "subtracting" objects can just have their
diameters increased by that delta, which I think will work nicely.

So I basically want to do a for loop from within cutCyl, but the actual for
loop version doesn't work. I had a suspicion that the for loop was affecting
the object tree, but I'm not exactly sure how. So I tried to unroll the for
loop manually, and this does work. 

So my question is now "How do I modify cutCyl so that it can accept the for
looped version here?"

(As an aside, I have been writing openscad code the same way I am used to
writing C, with the opening braces on the next line. However, I defer to the
style guide of the language of course, is this generally frowned upon?
Should I adopt the style I have seen in examples in this thread?)

Thank you!!

Sent from: http://forum.openscad.org/

More information about the Discuss mailing list