[OpenSCAD] Why doesn't this use statement work?

Rogier Wolff R.E.Wolff at BitWizard.nl
Sun Apr 1 04:07:07 EDT 2018


On Fri, Mar 30, 2018 at 06:19:27PM +0100, nop head wrote:
> I don't think you can generate objects in a loop. It is always a single
> object because the results are implicitly unioned.

In that case, that's a hint we should think about possibly chaiging
things in the language. 

The C language was designed so that the basic functions do things that
are useful, but also that they don't do too much. For example, printf
does not automatically add a newline. writing a function to add that
is easy, building something that removes the newline is not.

So.... a list of objects is easily unioned by adding union in
front, while a unioned list is not easily un-unioned. 

for (i=[0:10:50])
   translate ([i,i,0]) cube (15);

should give me the list of 6 cubes,  while 
union () {
  for (i=[0:10:50])
    translate ([i,i,0]) cube (15);
  }

gives the union of those objects. 

Roger. 

> 
> On 30 March 2018 at 16:08, jamcultur <nyponen at gmail.com> wrote:
> 
> > nophead wrote
> > >>children() doesn't work with objects generated in a for loop
> > >
> > > Well yes and no. A for loop produces a union of all its iterations, so
> > > only
> > > produces one child. I think modules do the same. Nothing can return
> > > multiple children, you can only pass them explicitly as a list.
> > >
> > > But for this case it would work to decouple part1 and part 2.
> > >
> > > part1.scad___________
> > >
> > > module part1() {
> > >     echo("part1");
> > >     children();
> > > }
> > > ____________________
> > >
> > >
> > > part2.scad___________
> > >
> > > module part2() {
> > >     echo("part2");
> > > }
> > > ____________________
> > >
> > >
> > > part_test.scad_________
> > >
> > > use
> > > <part1.scad>
> > > use
> > > <part2.scad>
> > > part1() part2();
> >
> > I haven't tested this yet to see if it will work with my code that
> > generates
> > objects in a loop, but I will. Thanks.
> >
> >
> >
> >
> > --
> > Sent from: http://forum.openscad.org/
> >
> > _______________________________________________
> > OpenSCAD mailing list
> > Discuss at lists.openscad.org
> > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
> >

> _______________________________________________
> OpenSCAD mailing list
> Discuss at lists.openscad.org
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


-- 
** R.E.Wolff at BitWizard.nl ** http://www.BitWizard.nl/ ** +31-15-2600998 **
**    Delftechpark 26 2628 XH  Delft, The Netherlands. KVK: 27239233    **
*-- BitWizard writes Linux device drivers for any device you may have! --*
The plan was simple, like my brother-in-law Phil. But unlike
Phil, this plan just might work.



More information about the Discuss mailing list