discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

simple accumulator question....

M
macdarren
Wed, Apr 10, 2019 1:09 AM

I have model in which I create multiple patterns of drill holes.

The pattern and thus the number of holes is optimized for the model size and
"drill size" and other parameters.

The final number of holes drilled is based on a nested group of operations
each fitting in the best pattern.  Each hole is separately positioned and
differenced out.

What I want to do is have an accumulator such that each time a cylinder
difference is created to 'drill' a hole I want accumulate the volume of
material removed or at least the area that is cut.

Traditionally this would be done something like:

             cut_volume = cut_volume + volume_of_new_cut

Now as I understand it this won't work in OpenSCAD....or maybe I am wrong...

Any suggestions about how to implement this...I don't really want to change
the mechanism for d calculating the holes, I just want to add some code to
keep track and echo the result.

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

I have model in which I create multiple patterns of drill holes. The pattern and thus the number of holes is optimized for the model size and "drill size" and other parameters. The final number of holes drilled is based on a nested group of operations each fitting in the best pattern. Each hole is separately positioned and differenced out. What I want to do is have an accumulator such that each time a cylinder difference is created to 'drill' a hole I want accumulate the volume of material removed or at least the area that is cut. Traditionally this would be done something like: cut_volume = cut_volume + volume_of_new_cut Now as I understand it this won't work in OpenSCAD....or maybe I am wrong... Any suggestions about how to implement this...I don't really want to change the mechanism for d calculating the holes, I just want to add some code to keep track and echo the result. -- Sent from: http://forum.openscad.org/
T
Troberg
Wed, Apr 10, 2019 6:35 AM

That would work, as long as the variable is declared on a global scope. I do
it to calculate cost and weight.

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

That would work, as long as the variable is declared on a global scope. I do it to calculate cost and weight. -- Sent from: http://forum.openscad.org/
M
macdarren
Wed, Apr 10, 2019 3:40 PM

I must be doing something wrong.....

I get only one accumulation them despite multiple adds the value never
changes.
Based on my understanding one Scad this is how it works....so there must be
a trick here I don't grasp.

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

I must be doing something wrong..... I get only one accumulation them despite multiple adds the value never changes. Based on my understanding one Scad this is how it works....so there must be a trick here I don't grasp. -- Sent from: http://forum.openscad.org/
NH
nop head
Wed, Apr 10, 2019 3:46 PM

You can't accumulate in openscad variables, I don't know why Troberg said
you can.

On Wed, 10 Apr 2019 at 16:40, macdarren macdarren@mac.com wrote:

I must be doing something wrong.....

I get only one accumulation them despite multiple adds the value never
changes.
Based on my understanding one Scad this is how it works....so there must be
a trick here I don't grasp.

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


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

You can't accumulate in openscad variables, I don't know why Troberg said you can. On Wed, 10 Apr 2019 at 16:40, macdarren <macdarren@mac.com> wrote: > I must be doing something wrong..... > > I get only one accumulation them despite multiple adds the value never > changes. > Based on my understanding one Scad this is how it works....so there must be > a trick here I don't grasp. > > > > > > -- > Sent from: http://forum.openscad.org/ > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
DM
Doug Moen
Wed, Apr 10, 2019 3:48 PM

You were right the first time.
cut_volume = cut_volume + volume_of_new_cut
does not work in OpenSCAD. It doesn't work in any context.

On Wed, Apr 10, 2019, at 11:40 AM, macdarren wrote:

I must be doing something wrong.....

I get only one accumulation them despite multiple adds the value never
changes.
Based on my understanding one Scad this is how it works....so there must be
a trick here I don't grasp.

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


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

You were right the first time. cut_volume = cut_volume + volume_of_new_cut does not work in OpenSCAD. It doesn't work in any context. On Wed, Apr 10, 2019, at 11:40 AM, macdarren wrote: > I must be doing something wrong..... > > I get only one accumulation them despite multiple adds the value never > changes. > Based on my understanding one Scad this is how it works....so there must be > a trick here I don't grasp. > > > > > > -- > Sent from: http://forum.openscad.org/ > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
NH
nop head
Wed, Apr 10, 2019 3:51 PM

You can accumulate in C style for loops in list comprehensions.

echo ([for(i = 0, t = 0; i < 10; t = t + i, i = i + 1) if(i == 9) t][0]);

ECHO: 36

On Wed, 10 Apr 2019 at 16:46, nop head nop.head@gmail.com wrote:

You can't accumulate in openscad variables, I don't know why Troberg said
you can.

On Wed, 10 Apr 2019 at 16:40, macdarren macdarren@mac.com wrote:

I must be doing something wrong.....

I get only one accumulation them despite multiple adds the value never
changes.
Based on my understanding one Scad this is how it works....so there must
be
a trick here I don't grasp.

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


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

You can accumulate in C style for loops in list comprehensions. echo ([for(i = 0, t = 0; i < 10; t = t + i, i = i + 1) if(i == 9) t][0]); ECHO: 36 On Wed, 10 Apr 2019 at 16:46, nop head <nop.head@gmail.com> wrote: > You can't accumulate in openscad variables, I don't know why Troberg said > you can. > > > > On Wed, 10 Apr 2019 at 16:40, macdarren <macdarren@mac.com> wrote: > >> I must be doing something wrong..... >> >> I get only one accumulation them despite multiple adds the value never >> changes. >> Based on my understanding one Scad this is how it works....so there must >> be >> a trick here I don't grasp. >> >> >> >> >> >> -- >> Sent from: http://forum.openscad.org/ >> >> _______________________________________________ >> OpenSCAD mailing list >> Discuss@lists.openscad.org >> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >> >
M
macdarren
Wed, Apr 10, 2019 3:54 PM

Hmm that looks promising...I use for loops for each section so if I can even
get subsection totals that would be a big improvement...I will try to
implement this and see what happens.

Thanks

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

Hmm that looks promising...I use for loops for each section so if I can even get subsection totals that would be a big improvement...I will try to implement this and see what happens. Thanks -- Sent from: http://forum.openscad.org/
A
adrianv
Wed, Apr 10, 2019 10:35 PM

Nobody has mentioned the normal way of accumulating, which is to use
recursion.  I don't know if you can apply this to your situation, though.

function sumsqr(n,total=0) = n==0 ? total : sumsqr(n-1,total+n*n);

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

Nobody has mentioned the normal way of accumulating, which is to use recursion. I don't know if you can apply this to your situation, though. function sumsqr(n,total=0) = n==0 ? total : sumsqr(n-1,total+n*n); -- Sent from: http://forum.openscad.org/
T
Troberg
Thu, Apr 11, 2019 9:04 AM

nophead wrote

You can't accumulate in openscad variables, I don't know why Troberg said
you can.

You are right, I just checked my code. I log the numbers, and then add stuff
from the log in a separate program. Sorry!

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

nophead wrote > You can't accumulate in openscad variables, I don't know why Troberg said > you can. You are right, I just checked my code. I log the numbers, and then add stuff from the log in a separate program. Sorry! -- Sent from: http://forum.openscad.org/