discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

How to place items in a loop

BR
Bob Roos
Wed, May 21, 2025 9:02 PM

Hello OpenSCAD,

I want to create a bunch of objects and I have the width of each object in a list.

how can I accumulate the total of the widths to the Nth point so I can place the new object to the right of the ones placed so far?

I understand that W += currentWidth+3  is not valid on OpenSCAD

--
Best regards,
Bob                          mailto:roosbob@wybatap.com

Hello OpenSCAD, I want to create a bunch of objects and I have the width of each object in a list. how can I accumulate the total of the widths to the Nth point so I can place the new object to the right of the ones placed so far? I understand that W += currentWidth+3 is not valid on OpenSCAD -- Best regards, Bob mailto:roosbob@wybatap.com
AM
Adrian Mariano
Wed, May 21, 2025 9:12 PM

You have to write a recursive function that computes the cumulative sum
list.  There is a cumsum() function in BOSL2 for this.

On Wed, May 21, 2025 at 5:02 PM Bob Roos via Discuss <
discuss@lists.openscad.org> wrote:

Hello OpenSCAD,

I want to create a bunch of objects and I have the width of each object
in a list.

how can I accumulate the total of the widths to the Nth point so I can
place the new object to the right of the ones placed so far?

I understand that W += currentWidth+3  is not valid on OpenSCAD

--
Best regards,
Bob                          mailto:roosbob@wybatap.com


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

You have to write a recursive function that computes the cumulative sum list. There is a cumsum() function in BOSL2 for this. On Wed, May 21, 2025 at 5:02 PM Bob Roos via Discuss < discuss@lists.openscad.org> wrote: > Hello OpenSCAD, > > I want to create a bunch of objects and I have the width of each object > in a list. > > how can I accumulate the total of the widths to the Nth point so I can > place the new object to the right of the ones placed so far? > > I understand that W += currentWidth+3 is not valid on OpenSCAD > > -- > Best regards, > Bob mailto:roosbob@wybatap.com > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
BR
Bob Roos
Thu, May 22, 2025 11:12 AM

Hi Adrian,

Thank you very much.  I learned something new and explored some of the list related functions (idx & list)

Wednesday, May 21, 2025, 5:12:58 PM, you wrote:

You have to write a recursive function that computes the cumulative sum list.  There is a cumsum() function in BOSL2 for this.

On Wed, May 21, 2025 at 5:02 PM Bob Roos via Discuss discuss@lists.openscad.org wrote:

Hello OpenSCAD,

  I want to create a bunch of objects and I have the width of each object in a list.

how can I accumulate the total of the widths to the Nth point so I can place the new object to the right of the ones placed so far?

I understand that W += currentWidth+3  is not valid on OpenSCAD

-- 
have Fun,
 Bob                           mailto:roosbob@wybatap.com

Hi Adrian, Thank you very much.  I learned something new and explored some of the list related functions (idx & list) Wednesday, May 21, 2025, 5:12:58 PM, you wrote: > You have to write a recursive function that computes the cumulative sum list.  There is a cumsum() function in BOSL2 for this. > On Wed, May 21, 2025 at 5:02 PM Bob Roos via Discuss <discuss@lists.openscad.org> wrote: >> Hello OpenSCAD, >>   I want to create a bunch of objects and I have the width of each object in a list. >> how can I accumulate the total of the widths to the Nth point so I can place the new object to the right of the ones placed so far? >> I understand that W += currentWidth+3  is not valid on OpenSCAD --  have Fun,  Bob                           mailto:roosbob@wybatap.com