# What is happening here?

38 messages
12
Open this post in threaded view
|

## What is happening here?

 I have some difficulty with modules and child calls. Suppose you want to repeat an object several times, you can write:    module repeat_y()    { for(i=[0:3])       translate([0,5*i,0])         child(0);  }    repeat_y()    { cube(1); } And if you have more objects to repeat you can extend it like:    module repeat_y()    { for(i=[0:3])       translate([0,5*i,0])         for (j = [0:\$children-1]) child(j);  }    repeat_y()    { cube(1);      sphere(1); } Up to here, no problems, suppose now, you want to repeat in the other direction as well, so now we have:    module repeat_y()    { for(i=[0:3])       translate([0,5*i,0])         for (j = [0:\$children-1]) child(j);  }    module repeat_x()    { for(i=[0:3])       translate([5*i,0,0])         repeat_y()           for (j = [0:\$children-1]) child(j); }    repeat_x()    { cube(1);      sphere(1); } Hey, where did the spheres go? We only see cubes! This can be repaired with a union() in the base call,    repeat_x()    { union()      { cube(1);        sphere(1); } } which is understandable but it is somewhat unexpected that it is needed. However, an union() inside the repeat_x module, i.e. the does NOT display the spheres:    module repeat_x()    { for(i=[0:3])       translate([5*i,0,0])         repeat_y()         { union()           { for (j = [0:\$children-1]) child(j); } } }    repeat_x()    { cube(1);      sphere(1); } And even more strangely, the following (adding ';' to union() ) does:    module repeat_x()    { for(i=[0:3])       translate([5*i,0,0])         repeat_y()         { union();           for (j = [0:\$children-1]) child(j); } } You could even replace union(); with something like sin(1); and it does still display the spheres. What is going on behind the scene's? Is this intended behavior? How should you predictably (and reliably) unify all child objects before they are past on to the next module? And why is this not done by the implicit 'union' as a result of the 'for' loop? Thank you for your insights. Ruud _______________________________________________ OpenSCAD mailing list [hidden email] http://rocklinux.net/mailman/listinfo/openscadhttp://openscad.org - https://flattr.com/thing/121566
Open this post in threaded view
|

## Re: What is happening here?

 seem to think the  child() only accepts the first object as the child and not subsequent ones  repeat_x()    { cubeandsphere();}module cubeandsphere() { cube(1);     sphere(1); } iirc will work around it and draw both  i would say its a bug Dave On Fri, Jul 19, 2013 at 1:12 PM, Ruud Vlaming wrote: I have some difficulty with modules and child calls. Suppose you want to repeat an object several times, you can write:    module repeat_y()    { for(i=[0:3])       translate([0,5*i,0])         child(0);  }    repeat_y()    { cube(1); } And if you have more objects to repeat you can extend it like:    module repeat_y()    { for(i=[0:3])       translate([0,5*i,0])         for (j = [0:\$children-1]) child(j);  }    repeat_y()    { cube(1);      sphere(1); } Up to here, no problems, suppose now, you want to repeat in the other direction as well, so now we have:    module repeat_y()    { for(i=[0:3])       translate([0,5*i,0])         for (j = [0:\$children-1]) child(j);  }    module repeat_x()    { for(i=[0:3])       translate([5*i,0,0])         repeat_y()           for (j = [0:\$children-1]) child(j); }    repeat_x()    { cube(1);      sphere(1); } Hey, where did the spheres go? We only see cubes! This can be repaired with a union() in the base call,    repeat_x()    { union()      { cube(1);        sphere(1); } } which is understandable but it is somewhat unexpected that it is needed. However, an union() inside the repeat_x module, i.e. the does NOT display the spheres:    module repeat_x()    { for(i=[0:3])       translate([5*i,0,0])         repeat_y()         { union()           { for (j = [0:\$children-1]) child(j); } } }    repeat_x()    { cube(1);      sphere(1); } And even more strangely, the following (adding ';' to union() ) does:    module repeat_x()    { for(i=[0:3])       translate([5*i,0,0])         repeat_y()         { union();           for (j = [0:\$children-1]) child(j); } } You could even replace union(); with something like sin(1); and it does still display the spheres. What is going on behind the scene's? Is this intended behavior? How should you predictably (and reliably) unify all child objects before they are past on to the next module? And why is this not done by the implicit 'union' as a result of the 'for' loop? Thank you for your insights. Ruud _______________________________________________ OpenSCAD mailing list [hidden email] http://rocklinux.net/mailman/listinfo/openscad http://openscad.org - https://flattr.com/thing/121566 _______________________________________________ OpenSCAD mailing list [hidden email] http://rocklinux.net/mailman/listinfo/openscadhttp://openscad.org - https://flattr.com/thing/121566
Open this post in threaded view
|

## Re: What is happening here?

Open this post in threaded view
|

## Re: What is happening here?

Open this post in threaded view
|

## Re: What is happening here?

Open this post in threaded view
|

## Re: What is happening here?

Open this post in threaded view
|

## Re: What is happening here?

Open this post in threaded view
|

## Re: What is happening here?

Open this post in threaded view
|

## Re: What is happening here?

Open this post in threaded view
|

## Re: What is happening here?

Open this post in threaded view
|

## Re: What is happening here?

 In reply to this post by nophead On 19-07-13 14:52, nop head wrote: > This fixes it: >     module repeat_x() > { kids = \$children; >       for(i=[0:3]) >             translate([5*i,0,0]) >                   repeat_y() >                        for(i = [0:kids - 1]) child(i); > } Did you actually try this fix? Although your analysis seems correct (see my other post) this fix does not work in my version of openSCAD (2013.06.19). It gives:    Compiling design (CSG Tree generation)...    Compiling design (CSG Products generation)...    ERROR: CSG generation failed! (no top level object found) Ruud _______________________________________________ OpenSCAD mailing list [hidden email] http://rocklinux.net/mailman/listinfo/openscadhttp://openscad.org - https://flattr.com/thing/121566
Open this post in threaded view
|

## Re: What is happening here?

Open this post in threaded view
|

## Re: What is happening here?

Open this post in threaded view
|

## Re: What is happening here?

 On 20-07-13 16:42, nop head wrote: > Yes I tested it. As I said in a later post it works on 2013.06.02 but > not on 2013.06.14. There were some changes about how variables are > evaluated and I don't think any version gets it completely correct yet. Okay, i see it now, thanks. This one entered my email just recently. It is a pity your workaround does not work for all versions, for displacing the inner module call is not possible in all situations. My code was just a simple example of something i encountered when designing something. _______________________________________________ OpenSCAD mailing list [hidden email] http://rocklinux.net/mailman/listinfo/openscadhttp://openscad.org - https://flattr.com/thing/121566
Open this post in threaded view
|

## Re: What is happening here?

 Yes not being able to copy the value of \$children seems like another unrelated bug.On 20 July 2013 15:48, Ruud Vlaming wrote: On 20-07-13 16:42, nop head wrote: > Yes I tested it. As I said in a later post it works on 2013.06.02 but > not on 2013.06.14. There were some changes about how variables are > evaluated and I don't think any version gets it completely correct yet. Okay, i see it now, thanks. This one entered my email just recently. It is a pity your workaround does not work for all versions, for displacing the inner module call is not possible in all situations. My code was just a simple example of something i encountered when designing something. _______________________________________________ OpenSCAD mailing list [hidden email] http://rocklinux.net/mailman/listinfo/openscad http://openscad.org - https://flattr.com/thing/121566 _______________________________________________ OpenSCAD mailing list [hidden email] http://rocklinux.net/mailman/listinfo/openscadhttp://openscad.org - https://flattr.com/thing/121566
Open this post in threaded view
|

## Re: What is happening here?

 Seems to behave like \$children is assigned a value after all the other local variables in the module. On 20 July 2013 15:50, nop head wrote: Yes not being able to copy the value of \$children seems like another unrelated bug. On 20 July 2013 15:48, Ruud Vlaming wrote: On 20-07-13 16:42, nop head wrote: > Yes I tested it. As I said in a later post it works on 2013.06.02 but > not on 2013.06.14. There were some changes about how variables are > evaluated and I don't think any version gets it completely correct yet. Okay, i see it now, thanks. This one entered my email just recently. It is a pity your workaround does not work for all versions, for displacing the inner module call is not possible in all situations. My code was just a simple example of something i encountered when designing something. _______________________________________________ OpenSCAD mailing list [hidden email] http://rocklinux.net/mailman/listinfo/openscad http://openscad.org - https://flattr.com/thing/121566 _______________________________________________ OpenSCAD mailing list [hidden email] http://rocklinux.net/mailman/listinfo/openscadhttp://openscad.org - https://flattr.com/thing/121566
Open this post in threaded view
|

## Re: What is happening here?

 Are you guys saying this is a regression which appeared _after_ the last public release? That would make sense as some experimental stuff were enabled post-release.  -Marius _______________________________________________ OpenSCAD mailing list [hidden email] http://rocklinux.net/mailman/listinfo/openscadhttp://openscad.org - https://flattr.com/thing/121566
Open this post in threaded view
|

## Re: What is happening here?

 In reply to this post by nophead BTW, you have two nested for loops both with the variable 'i' in there. But i assume this is just a typo? Ruud. On 20-07-13 16:42, nop head wrote: >     On 19-07-13 14:52, nop head wrote: >      > This fixes it: >      >     module repeat_x() >      > { kids = \$children; >      >       for(i=[0:3]) variable i >      >             translate([5*i,0,0]) >      >                   repeat_y() >      >                        for(i = [0:kids - 1]) child(i); variable i again! >      > } _______________________________________________ OpenSCAD mailing list [hidden email] http://rocklinux.net/mailman/listinfo/openscadhttp://openscad.org - https://flattr.com/thing/121566
Open this post in threaded view
|