discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

How to get at individual children?

X
xenomachina
Mon, Feb 23, 2015 11:02 PM

Hello. I'm trying to write a module that will perform an operation on subsets
of its children. I tried using children() with an index, but this still
seems to give me all of the children. I'm seeing this behavior both with
2013.01+dfsg-2.2 (the latest binary in the Ubuntu 14.04 repo) and a build I
did myself from git commit 0dd3f004dd66798faef42ab4edaa72c12dc0ad66.

Here's a simplified version of what I'm trying that illustrates the problem:

module first() {
    child(0);
}

first() {
    for(i=[0:20:120]) {
        rotate([0,0,i]) translate([10,0,0]) cylinder();
    }
}

The for loop generates 7 cylinders in an arc. I would expect the "first"
module to then ignore all of them except the first, so I expect to see only
one cylinder. Instead I see all 7.

I have tried using children() instead of child() and I have also tried using
index=0 instead of just 0 as the parameter. Either way, the result is the
same (except some don't compile on the older OpenSCAD binary).

Any ideas what I'm doing wrong?

--
View this message in context: http://forum.openscad.org/How-to-get-at-individual-children-tp11738.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Hello. I'm trying to write a module that will perform an operation on subsets of its children. I tried using children() with an index, but this still seems to give me all of the children. I'm seeing this behavior both with 2013.01+dfsg-2.2 (the latest binary in the Ubuntu 14.04 repo) and a build I did myself from git commit 0dd3f004dd66798faef42ab4edaa72c12dc0ad66. Here's a simplified version of what I'm trying that illustrates the problem: module first() { child(0); } first() { for(i=[0:20:120]) { rotate([0,0,i]) translate([10,0,0]) cylinder(); } } The for loop generates 7 cylinders in an arc. I would expect the "first" module to then ignore all of them except the first, so I expect to see only one cylinder. Instead I see all 7. I have tried using children() instead of child() and I have also tried using index=0 instead of just 0 as the parameter. Either way, the result is the same (except some don't compile on the older OpenSCAD binary). Any ideas what I'm doing wrong? -- View this message in context: http://forum.openscad.org/How-to-get-at-individual-children-tp11738.html Sent from the OpenSCAD mailing list archive at Nabble.com.
MH
Miro Hrončok
Mon, Feb 23, 2015 11:06 PM

You ar enot doing anything wrong, there is an implicit union()
happening after for().

See the note here:
http://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Conditional_and_Iterator_Functions#Intersection_For_Loop

And see this: https://github.com/openscad/openscad/issues/350

Miro Hrončok

Telefon: +420777974800

2015-02-24 0:02 GMT+01:00 xenomachina from-openscad@xenomachina.com:

Hello. I'm trying to write a module that will perform an operation on subsets
of its children. I tried using children() with an index, but this still
seems to give me all of the children. I'm seeing this behavior both with
2013.01+dfsg-2.2 (the latest binary in the Ubuntu 14.04 repo) and a build I
did myself from git commit 0dd3f004dd66798faef42ab4edaa72c12dc0ad66.

Here's a simplified version of what I'm trying that illustrates the problem:

 module first() {
     child(0);
 }

 first() {
     for(i=[0:20:120]) {
         rotate([0,0,i]) translate([10,0,0]) cylinder();
     }
 }

The for loop generates 7 cylinders in an arc. I would expect the "first"
module to then ignore all of them except the first, so I expect to see only
one cylinder. Instead I see all 7.

I have tried using children() instead of child() and I have also tried using
index=0 instead of just 0 as the parameter. Either way, the result is the
same (except some don't compile on the older OpenSCAD binary).

Any ideas what I'm doing wrong?

--
View this message in context: http://forum.openscad.org/How-to-get-at-individual-children-tp11738.html
Sent from the OpenSCAD mailing list archive at Nabble.com.


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

You ar enot doing anything wrong, there is an implicit union() happening after for(). See the note here: http://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Conditional_and_Iterator_Functions#Intersection_For_Loop And see this: https://github.com/openscad/openscad/issues/350 Miro Hrončok Telefon: +420777974800 2015-02-24 0:02 GMT+01:00 xenomachina <from-openscad@xenomachina.com>: > Hello. I'm trying to write a module that will perform an operation on subsets > of its children. I tried using children() with an index, but this still > seems to give me all of the children. I'm seeing this behavior both with > 2013.01+dfsg-2.2 (the latest binary in the Ubuntu 14.04 repo) and a build I > did myself from git commit 0dd3f004dd66798faef42ab4edaa72c12dc0ad66. > > Here's a simplified version of what I'm trying that illustrates the problem: > > module first() { > child(0); > } > > first() { > for(i=[0:20:120]) { > rotate([0,0,i]) translate([10,0,0]) cylinder(); > } > } > > The for loop generates 7 cylinders in an arc. I would expect the "first" > module to then ignore all of them except the first, so I expect to see only > one cylinder. Instead I see all 7. > > I have tried using children() instead of child() and I have also tried using > index=0 instead of just 0 as the parameter. Either way, the result is the > same (except some don't compile on the older OpenSCAD binary). > > Any ideas what I'm doing wrong? > > > > -- > View this message in context: http://forum.openscad.org/How-to-get-at-individual-children-tp11738.html > Sent from the OpenSCAD mailing list archive at Nabble.com. > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
NH
nop head
Mon, Feb 23, 2015 11:13 PM

The problem is for always unions it children so there is only ever one
child of first() and that is the for() node.

On 23 February 2015 at 23:02, xenomachina from-openscad@xenomachina.com
wrote:

Hello. I'm trying to write a module that will perform an operation on
subsets
of its children. I tried using children() with an index, but this still
seems to give me all of the children. I'm seeing this behavior both with
2013.01+dfsg-2.2 (the latest binary in the Ubuntu 14.04 repo) and a build I
did myself from git commit 0dd3f004dd66798faef42ab4edaa72c12dc0ad66.

Here's a simplified version of what I'm trying that illustrates the
problem:

 module first() {
     child(0);
 }

 first() {
     for(i=[0:20:120]) {
         rotate([0,0,i]) translate([10,0,0]) cylinder();
     }
 }

The for loop generates 7 cylinders in an arc. I would expect the "first"
module to then ignore all of them except the first, so I expect to see only
one cylinder. Instead I see all 7.

I have tried using children() instead of child() and I have also tried
using
index=0 instead of just 0 as the parameter. Either way, the result is the
same (except some don't compile on the older OpenSCAD binary).

Any ideas what I'm doing wrong?

--
View this message in context:
http://forum.openscad.org/How-to-get-at-individual-children-tp11738.html
Sent from the OpenSCAD mailing list archive at Nabble.com.


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

The problem is for always unions it children so there is only ever one child of first() and that is the for() node. On 23 February 2015 at 23:02, xenomachina <from-openscad@xenomachina.com> wrote: > Hello. I'm trying to write a module that will perform an operation on > subsets > of its children. I tried using children() with an index, but this still > seems to give me all of the children. I'm seeing this behavior both with > 2013.01+dfsg-2.2 (the latest binary in the Ubuntu 14.04 repo) and a build I > did myself from git commit 0dd3f004dd66798faef42ab4edaa72c12dc0ad66. > > Here's a simplified version of what I'm trying that illustrates the > problem: > > module first() { > child(0); > } > > first() { > for(i=[0:20:120]) { > rotate([0,0,i]) translate([10,0,0]) cylinder(); > } > } > > The for loop generates 7 cylinders in an arc. I would expect the "first" > module to then ignore all of them except the first, so I expect to see only > one cylinder. Instead I see all 7. > > I have tried using children() instead of child() and I have also tried > using > index=0 instead of just 0 as the parameter. Either way, the result is the > same (except some don't compile on the older OpenSCAD binary). > > Any ideas what I'm doing wrong? > > > > -- > View this message in context: > http://forum.openscad.org/How-to-get-at-individual-children-tp11738.html > Sent from the OpenSCAD mailing list archive at Nabble.com. > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
X
xenomachina
Tue, Feb 24, 2015 8:53 PM

Ah, I see. Thanks.

Is there any workaround for this behavior? I tried rebuilding OpenSCAD in
the issue350 branch and running it with the  --enable=lazy-union flag, but
it still gives me 7 cylinders.

On Mon, Feb 23, 2015 at 3:07 PM, Miro Hrončok [via OpenSCAD] <
ml-node+s1091067n11739h62@n5.nabble.com> wrote:

You ar enot doing anything wrong, there is an implicit union()
happening after for().

See the note here:

http://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Conditional_and_Iterator_Functions#Intersection_For_Loop

And see this: https://github.com/openscad/openscad/issues/350

Miro Hrončok

Telefon: +420777974800

2015-02-24 0:02 GMT+01:00 xenomachina <[hidden email]
http:///user/SendEmail.jtp?type=node&node=11739&i=0>:

Hello. I'm trying to write a module that will perform an operation on

subsets

of its children. I tried using children() with an index, but this still
seems to give me all of the children. I'm seeing this behavior both with
2013.01+dfsg-2.2 (the latest binary in the Ubuntu 14.04 repo) and a

build I

did myself from git commit 0dd3f004dd66798faef42ab4edaa72c12dc0ad66.

Here's a simplified version of what I'm trying that illustrates the

problem:

 module first() {
     child(0);
 }

 first() {
     for(i=[0:20:120]) {
         rotate([0,0,i]) translate([10,0,0]) cylinder();
     }
 }

The for loop generates 7 cylinders in an arc. I would expect the "first"
module to then ignore all of them except the first, so I expect to see

only

one cylinder. Instead I see all 7.

I have tried using children() instead of child() and I have also tried

using

index=0 instead of just 0 as the parameter. Either way, the result is

the

same (except some don't compile on the older OpenSCAD binary).

Any ideas what I'm doing wrong?

--
View this message in context:

Sent from the OpenSCAD mailing list archive at Nabble.com.


OpenSCAD mailing list
[hidden email] http:///user/SendEmail.jtp?type=node&node=11739&i=1
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


OpenSCAD mailing list
[hidden email] http:///user/SendEmail.jtp?type=node&node=11739&i=2
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


If you reply to this email, your message will be added to the discussion
below:

http://forum.openscad.org/How-to-get-at-individual-children-tp11738p11739.html
To unsubscribe from How to get at individual children?, click here
http://forum.openscad.org/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=11738&code=ZnJvbS1vcGVuc2NhZEB4ZW5vbWFjaGluYS5jb218MTE3Mzh8MjA2MDM4NDcyNA==
.
NAML
http://forum.openscad.org/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml

--
View this message in context: http://forum.openscad.org/How-to-get-at-individual-children-tp11738p11748.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Ah, I see. Thanks. Is there any workaround for this behavior? I tried rebuilding OpenSCAD in the issue350 branch and running it with the --enable=lazy-union flag, but it still gives me 7 cylinders. On Mon, Feb 23, 2015 at 3:07 PM, Miro Hrončok [via OpenSCAD] < ml-node+s1091067n11739h62@n5.nabble.com> wrote: > You ar enot doing anything wrong, there is an implicit union() > happening after for(). > > See the note here: > > http://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Conditional_and_Iterator_Functions#Intersection_For_Loop > > And see this: https://github.com/openscad/openscad/issues/350 > > Miro Hrončok > > Telefon: +420777974800 > > > 2015-02-24 0:02 GMT+01:00 xenomachina <[hidden email] > <http:///user/SendEmail.jtp?type=node&node=11739&i=0>>: > > > Hello. I'm trying to write a module that will perform an operation on > subsets > > of its children. I tried using children() with an index, but this still > > seems to give me all of the children. I'm seeing this behavior both with > > 2013.01+dfsg-2.2 (the latest binary in the Ubuntu 14.04 repo) and a > build I > > did myself from git commit 0dd3f004dd66798faef42ab4edaa72c12dc0ad66. > > > > Here's a simplified version of what I'm trying that illustrates the > problem: > > > > module first() { > > child(0); > > } > > > > first() { > > for(i=[0:20:120]) { > > rotate([0,0,i]) translate([10,0,0]) cylinder(); > > } > > } > > > > The for loop generates 7 cylinders in an arc. I would expect the "first" > > module to then ignore all of them except the first, so I expect to see > only > > one cylinder. Instead I see all 7. > > > > I have tried using children() instead of child() and I have also tried > using > > index=0 instead of just 0 as the parameter. Either way, the result is > the > > same (except some don't compile on the older OpenSCAD binary). > > > > Any ideas what I'm doing wrong? > > > > > > > > -- > > View this message in context: > http://forum.openscad.org/How-to-get-at-individual-children-tp11738.html > > Sent from the OpenSCAD mailing list archive at Nabble.com. > > > > _______________________________________________ > > OpenSCAD mailing list > > [hidden email] <http:///user/SendEmail.jtp?type=node&node=11739&i=1> > > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > > _______________________________________________ > OpenSCAD mailing list > [hidden email] <http:///user/SendEmail.jtp?type=node&node=11739&i=2> > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > > > ------------------------------ > If you reply to this email, your message will be added to the discussion > below: > > http://forum.openscad.org/How-to-get-at-individual-children-tp11738p11739.html > To unsubscribe from How to get at individual children?, click here > <http://forum.openscad.org/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=11738&code=ZnJvbS1vcGVuc2NhZEB4ZW5vbWFjaGluYS5jb218MTE3Mzh8MjA2MDM4NDcyNA==> > . > NAML > <http://forum.openscad.org/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> > -- View this message in context: http://forum.openscad.org/How-to-get-at-individual-children-tp11738p11748.html Sent from the OpenSCAD mailing list archive at Nabble.com.
NH
nop head
Tue, Feb 24, 2015 8:59 PM

No because children are not individual 3D objects, They are child nodes in
the syntax tree.

E.g.

child(1) {
a();
b();
c();
}

will select b(), which could generate many objects.

On 24 February 2015 at 20:53, xenomachina from-openscad@xenomachina.com
wrote:

Ah, I see. Thanks.

Is there any workaround for this behavior? I tried rebuilding OpenSCAD in
the issue350 branch and running it with the  --enable=lazy-union flag, but
it still gives me 7 cylinders.

On Mon, Feb 23, 2015 at 3:07 PM, Miro Hrončok [via OpenSCAD] <[hidden
email] http:///user/SendEmail.jtp?type=node&node=11748&i=0> wrote:

You ar enot doing anything wrong, there is an implicit union()
happening after for().

See the note here:

http://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Conditional_and_Iterator_Functions#Intersection_For_Loop

And see this: https://github.com/openscad/openscad/issues/350

Miro Hrončok

Telefon: <a href="tel:%2B420777974800" value="+420777974800" target="_blank">+420777974800

2015-02-24 0:02 GMT+01:00 xenomachina <[hidden email]
http:///user/SendEmail.jtp?type=node&node=11739&i=0>:

Hello. I'm trying to write a module that will perform an operation on

subsets

of its children. I tried using children() with an index, but this still
seems to give me all of the children. I'm seeing this behavior both

with

2013.01+dfsg-2.2 (the latest binary in the Ubuntu 14.04 repo) and a

build I

did myself from git commit 0dd3f004dd66798faef42ab4edaa72c12dc0ad66.

Here's a simplified version of what I'm trying that illustrates the

problem:

 module first() {
     child(0);
 }

 first() {
     for(i=[0:20:120]) {
         rotate([0,0,i]) translate([10,0,0]) cylinder();
     }
 }

The for loop generates 7 cylinders in an arc. I would expect the

"first"

module to then ignore all of them except the first, so I expect to see

only

one cylinder. Instead I see all 7.

I have tried using children() instead of child() and I have also tried

using

index=0 instead of just 0 as the parameter. Either way, the result is

the

same (except some don't compile on the older OpenSCAD binary).

Any ideas what I'm doing wrong?

--
View this message in context:

Sent from the OpenSCAD mailing list archive at Nabble.com.


OpenSCAD mailing list
[hidden email] http:///user/SendEmail.jtp?type=node&node=11739&i=1
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


View this message in context: Re: How to get at individual children?
http://forum.openscad.org/How-to-get-at-individual-children-tp11738p11748.html

Sent from the OpenSCAD mailing list archive http://forum.openscad.org/
at Nabble.com.


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

No because children are not individual 3D objects, They are child nodes in the syntax tree. E.g. child(1) { a(); b(); c(); } will select b(), which could generate many objects. On 24 February 2015 at 20:53, xenomachina <from-openscad@xenomachina.com> wrote: > Ah, I see. Thanks. > > Is there any workaround for this behavior? I tried rebuilding OpenSCAD in > the issue350 branch and running it with the --enable=lazy-union flag, but > it still gives me 7 cylinders. > > > On Mon, Feb 23, 2015 at 3:07 PM, Miro Hrončok [via OpenSCAD] <[hidden > email] <http:///user/SendEmail.jtp?type=node&node=11748&i=0>> wrote: > >> You ar enot doing anything wrong, there is an implicit union() >> happening after for(). >> >> See the note here: >> >> http://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Conditional_and_Iterator_Functions#Intersection_For_Loop >> >> And see this: https://github.com/openscad/openscad/issues/350 >> >> Miro Hrončok >> >> Telefon: <a href="tel:%2B420777974800" value="+420777974800" >> target="_blank">+420777974800 >> >> >> 2015-02-24 0:02 GMT+01:00 xenomachina <[hidden email] >> <http:///user/SendEmail.jtp?type=node&node=11739&i=0>>: >> >> > Hello. I'm trying to write a module that will perform an operation on >> subsets >> > of its children. I tried using children() with an index, but this still >> > seems to give me all of the children. I'm seeing this behavior both >> with >> > 2013.01+dfsg-2.2 (the latest binary in the Ubuntu 14.04 repo) and a >> build I >> > did myself from git commit 0dd3f004dd66798faef42ab4edaa72c12dc0ad66. >> > >> > Here's a simplified version of what I'm trying that illustrates the >> problem: >> > >> > module first() { >> > child(0); >> > } >> > >> > first() { >> > for(i=[0:20:120]) { >> > rotate([0,0,i]) translate([10,0,0]) cylinder(); >> > } >> > } >> > >> > The for loop generates 7 cylinders in an arc. I would expect the >> "first" >> > module to then ignore all of them except the first, so I expect to see >> only >> > one cylinder. Instead I see all 7. >> > >> > I have tried using children() instead of child() and I have also tried >> using >> > index=0 instead of just 0 as the parameter. Either way, the result is >> the >> > same (except some don't compile on the older OpenSCAD binary). >> > >> > Any ideas what I'm doing wrong? >> > >> > >> > >> > -- >> > View this message in context: >> http://forum.openscad.org/How-to-get-at-individual-children-tp11738.html >> > Sent from the OpenSCAD mailing list archive at Nabble.com. >> > >> > _______________________________________________ >> > OpenSCAD mailing list >> > [hidden email] <http:///user/SendEmail.jtp?type=node&node=11739&i=1> >> > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >> >> _______________________________________________ >> OpenSCAD mailing list >> [hidden email] <http:///user/SendEmail.jtp?type=node&node=11739&i=2> >> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >> >> >> ------------------------------ >> If you reply to this email, your message will be added to the >> discussion below: >> >> http://forum.openscad.org/How-to-get-at-individual-children-tp11738p11739.html >> To unsubscribe from How to get at individual children?, click here. >> NAML >> <http://forum.openscad.org/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> >> > > > ------------------------------ > View this message in context: Re: How to get at individual children? > <http://forum.openscad.org/How-to-get-at-individual-children-tp11738p11748.html> > > Sent from the OpenSCAD mailing list archive <http://forum.openscad.org/> > at Nabble.com. > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > >
X
xenomachina
Tue, Feb 24, 2015 10:10 PM

Yes, get that that's the behavior of for, though I honestly don't see how
the implicit union is desirable, except for backward compatibility.

What I'm asking is: how can I create a sequence of 3D objects in a loop,
and then iterate through them individually in a separate module? For
example, is there a way to get at the individual children of a union?

Here's a more concrete example of what I'd like to be able to do:

module hull_join() {
    union() {
        for_without_a_union (i=[0:$children - 2]) {
            hull() {
                children(index=i);
                children(index=i+1);
            }
        }
    }
}

hull_join() {
    for_without_a_union(i=[0:20:120]) {
        rotate([0,0,i]) translate([10,0,0]) cylinder();
    }
}

If for_without_a_union existed, then this would create a set of cylinders
in an arc and then hull_join would union together the hulls of each
adjacent pair producing a round arc path. See this combined screenshot:
https://imgur.com/MJjDlcY

To generate the left half of that screenshot I ended up manually unrolling
the loop, but I'm hoping there's a way to use/implement hull_join that
doesn't require unrolling loops, inlining the caller, or other sorts of
special-casing.

On Tue, Feb 24, 2015 at 12:59 PM, nophead [via OpenSCAD] <
ml-node+s1091067n11749h72@n5.nabble.com> wrote:

No because children are not individual 3D objects, They are child nodes in
the syntax tree.

E.g.

child(1) {
a();
b();
c();
}

will select b(), which could generate many objects.

On 24 February 2015 at 20:53, xenomachina <[hidden email]
http:///user/SendEmail.jtp?type=node&node=11749&i=0> wrote:

Ah, I see. Thanks.

Is there any workaround for this behavior? I tried rebuilding OpenSCAD in
the issue350 branch and running it with the  --enable=lazy-union flag, but
it still gives me 7 cylinders.

On Mon, Feb 23, 2015 at 3:07 PM, Miro Hrončok [via OpenSCAD] <[hidden
email] http:///user/SendEmail.jtp?type=node&node=11748&i=0> wrote:

You ar enot doing anything wrong, there is an implicit union()
happening after for().

See the note here:

http://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Conditional_and_Iterator_Functions#Intersection_For_Loop

And see this: https://github.com/openscad/openscad/issues/350

Miro Hrončok

Telefon: <a href="tel:%2B420777974800" value="<a href="tel:%2B420777974800" value="+420777974800" target="_blank">
+420777974800" target="_blank"><a href="tel:%2B420777974800" value=" +420777974800" target="_blank">+420777974800

2015-02-24 0:02 GMT+01:00 xenomachina <[hidden email]
http:///user/SendEmail.jtp?type=node&node=11739&i=0>:

Hello. I'm trying to write a module that will perform an operation on

subsets

of its children. I tried using children() with an index, but this

still

seems to give me all of the children. I'm seeing this behavior both

with

2013.01+dfsg-2.2 (the latest binary in the Ubuntu 14.04 repo) and a

build I

did myself from git commit 0dd3f004dd66798faef42ab4edaa72c12dc0ad66.

Here's a simplified version of what I'm trying that illustrates the

problem:

 module first() {
     child(0);
 }

 first() {
     for(i=[0:20:120]) {
         rotate([0,0,i]) translate([10,0,0]) cylinder();
     }
 }

The for loop generates 7 cylinders in an arc. I would expect the

"first"

module to then ignore all of them except the first, so I expect to see

only

one cylinder. Instead I see all 7.

I have tried using children() instead of child() and I have also tried

using

index=0 instead of just 0 as the parameter. Either way, the result is

the

same (except some don't compile on the older OpenSCAD binary).

Any ideas what I'm doing wrong?

--
View this message in context:

Sent from the OpenSCAD mailing list archive at Nabble.com.


OpenSCAD mailing list
[hidden email] http:///user/SendEmail.jtp?type=node&node=11739&i=1
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


View this message in context: Re: How to get at individual children?
http://forum.openscad.org/How-to-get-at-individual-children-tp11738p11748.html

Sent from the OpenSCAD mailing list archive http://forum.openscad.org/
at Nabble.com.


OpenSCAD mailing list
[hidden email] http:///user/SendEmail.jtp?type=node&node=11749&i=1
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


OpenSCAD mailing list
[hidden email] http:///user/SendEmail.jtp?type=node&node=11749&i=2
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


If you reply to this email, your message will be added to the discussion
below:

http://forum.openscad.org/How-to-get-at-individual-children-tp11738p11749.html
To unsubscribe from How to get at individual children?, click here
http://forum.openscad.org/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=11738&code=ZnJvbS1vcGVuc2NhZEB4ZW5vbWFjaGluYS5jb218MTE3Mzh8MjA2MDM4NDcyNA==
.
NAML
http://forum.openscad.org/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml

--
View this message in context: http://forum.openscad.org/How-to-get-at-individual-children-tp11738p11750.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Yes, get that that's the behavior of for, though I honestly don't see how the implicit union is desirable, except for backward compatibility. What I'm asking is: how can I create a sequence of 3D objects in a loop, and then iterate through them individually in a separate module? For example, is there a way to get at the individual children of a union? Here's a more concrete example of what I'd like to be able to do: module hull_join() { union() { for_without_a_union (i=[0:$children - 2]) { hull() { children(index=i); children(index=i+1); } } } } hull_join() { for_without_a_union(i=[0:20:120]) { rotate([0,0,i]) translate([10,0,0]) cylinder(); } } If for_without_a_union existed, then this would create a set of cylinders in an arc and then hull_join would union together the hulls of each adjacent pair producing a round arc path. See this combined screenshot: https://imgur.com/MJjDlcY To generate the left half of that screenshot I ended up manually unrolling the loop, but I'm hoping there's a way to use/implement hull_join that doesn't require unrolling loops, inlining the caller, or other sorts of special-casing. On Tue, Feb 24, 2015 at 12:59 PM, nophead [via OpenSCAD] < ml-node+s1091067n11749h72@n5.nabble.com> wrote: > No because children are not individual 3D objects, They are child nodes in > the syntax tree. > > E.g. > > child(1) { > a(); > b(); > c(); > } > > will select b(), which could generate many objects. > > On 24 February 2015 at 20:53, xenomachina <[hidden email] > <http:///user/SendEmail.jtp?type=node&node=11749&i=0>> wrote: > >> Ah, I see. Thanks. >> >> Is there any workaround for this behavior? I tried rebuilding OpenSCAD in >> the issue350 branch and running it with the --enable=lazy-union flag, but >> it still gives me 7 cylinders. >> >> >> On Mon, Feb 23, 2015 at 3:07 PM, Miro Hrončok [via OpenSCAD] <[hidden >> email] <http:///user/SendEmail.jtp?type=node&node=11748&i=0>> wrote: >> >>> You ar enot doing anything wrong, there is an implicit union() >>> happening after for(). >>> >>> See the note here: >>> >>> http://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Conditional_and_Iterator_Functions#Intersection_For_Loop >>> >>> And see this: https://github.com/openscad/openscad/issues/350 >>> >>> Miro Hrončok >>> >>> Telefon: <a href="tel:%2B420777974800" value="<a >>> href="tel:%2B420777974800" value="+420777974800" target="_blank"> >>> +420777974800" target="_blank"><a href="tel:%2B420777974800" value=" >>> +420777974800" target="_blank">+420777974800 >>> >>> >>> 2015-02-24 0:02 GMT+01:00 xenomachina <[hidden email] >>> <http:///user/SendEmail.jtp?type=node&node=11739&i=0>>: >>> >>> > Hello. I'm trying to write a module that will perform an operation on >>> subsets >>> > of its children. I tried using children() with an index, but this >>> still >>> > seems to give me all of the children. I'm seeing this behavior both >>> with >>> > 2013.01+dfsg-2.2 (the latest binary in the Ubuntu 14.04 repo) and a >>> build I >>> > did myself from git commit 0dd3f004dd66798faef42ab4edaa72c12dc0ad66. >>> > >>> > Here's a simplified version of what I'm trying that illustrates the >>> problem: >>> > >>> > module first() { >>> > child(0); >>> > } >>> > >>> > first() { >>> > for(i=[0:20:120]) { >>> > rotate([0,0,i]) translate([10,0,0]) cylinder(); >>> > } >>> > } >>> > >>> > The for loop generates 7 cylinders in an arc. I would expect the >>> "first" >>> > module to then ignore all of them except the first, so I expect to see >>> only >>> > one cylinder. Instead I see all 7. >>> > >>> > I have tried using children() instead of child() and I have also tried >>> using >>> > index=0 instead of just 0 as the parameter. Either way, the result is >>> the >>> > same (except some don't compile on the older OpenSCAD binary). >>> > >>> > Any ideas what I'm doing wrong? >>> > >>> > >>> > >>> > -- >>> > View this message in context: >>> http://forum.openscad.org/How-to-get-at-individual-children-tp11738.html >>> > Sent from the OpenSCAD mailing list archive at Nabble.com. >>> > >>> > _______________________________________________ >>> > OpenSCAD mailing list >>> > [hidden email] <http:///user/SendEmail.jtp?type=node&node=11739&i=1> >>> > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >>> >> _______________________________________________ >> OpenSCAD mailing list >> [hidden email] <http:///user/SendEmail.jtp?type=node&node=11739&i=2> >> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >> >> >> ------------------------------ >> If you reply to this email, your message will be added to the >> discussion below: >> >> http://forum.openscad.org/How-to-get-at-individual-children-tp11738p11739.html >> To unsubscribe from How to get at individual children?, click here. >> NAML >> <http://forum.openscad.org/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> >> > > > ------------------------------ > View this message in context: Re: How to get at individual children? > <http://forum.openscad.org/How-to-get-at-individual-children-tp11738p11748.html> > > Sent from the OpenSCAD mailing list archive <http://forum.openscad.org/> > at Nabble.com. > > _______________________________________________ > OpenSCAD mailing list > [hidden email] <http:///user/SendEmail.jtp?type=node&node=11749&i=1> > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > > > > _______________________________________________ > OpenSCAD mailing list > [hidden email] <http:///user/SendEmail.jtp?type=node&node=11749&i=2> > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > > > ------------------------------ > If you reply to this email, your message will be added to the discussion > below: > > http://forum.openscad.org/How-to-get-at-individual-children-tp11738p11749.html > To unsubscribe from How to get at individual children?, click here > <http://forum.openscad.org/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=11738&code=ZnJvbS1vcGVuc2NhZEB4ZW5vbWFjaGluYS5jb218MTE3Mzh8MjA2MDM4NDcyNA==> > . > NAML > <http://forum.openscad.org/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> > -- View this message in context: http://forum.openscad.org/How-to-get-at-individual-children-tp11738p11750.html Sent from the OpenSCAD mailing list archive at Nabble.com.
M
MichaelAtOz
Tue, Feb 24, 2015 10:27 PM

Have you considered recursion? (I haven't for your particular issue, brain
not awake yet)


Unless specifically shown otherwise above, my contribution is in the Public Domain; To the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. This work is published globally via the internet. :) Inclusion of works of previous authors is not included in the above.

The TPP is no simple “trade agreement.”  Fight it! http://www.ourfairdeal.org/

View this message in context: http://forum.openscad.org/How-to-get-at-individual-children-tp11738p11751.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Have you considered recursion? (I haven't for your particular issue, brain not awake yet) ----- Unless specifically shown otherwise above, my contribution is in the Public Domain; To the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. This work is published globally via the internet. :) Inclusion of works of previous authors is not included in the above. The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/ -- View this message in context: http://forum.openscad.org/How-to-get-at-individual-children-tp11738p11751.html Sent from the OpenSCAD mailing list archive at Nabble.com.
X
xenomachina
Tue, Feb 24, 2015 11:35 PM

That's an interesting idea!

I just tried this...

module segment(i, step, last) {
    rotate([0,0,i]) translate([10,0,0]) cylinder();
    if (i < last) segment(i + step, step, last);
}

hull_join() {
    segment(0, 20, 120);
}

... and I still end up with something that looks a like the right image.

Something still seems to be making an implicit union. Is there some other
approach that could avoid this?

On Tue, Feb 24, 2015 at 2:27 PM, MichaelAtOz [via OpenSCAD] <
ml-node+s1091067n11751h34@n5.nabble.com> wrote:

Have you considered recursion? (I haven't for your particular issue, brain
not awake yet)
Unless specifically shown otherwise above, my contribution is in the
Public Domain; To the extent possible under law, I have waived all
copyright and related or neighbouring rights to this work. This work is
published globally via the internet. :)
Inclusion of works of previous authors is not included in the above.
The TPP is no simple “trade agreement.” Fight it!
http://www.ourfairdeal.org/


If you reply to this email, your message will be added to the discussion
below:

http://forum.openscad.org/How-to-get-at-individual-children-tp11738p11751.html
To unsubscribe from How to get at individual children?, click here
http://forum.openscad.org/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=11738&code=ZnJvbS1vcGVuc2NhZEB4ZW5vbWFjaGluYS5jb218MTE3Mzh8MjA2MDM4NDcyNA==
.
NAML
http://forum.openscad.org/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml

--
View this message in context: http://forum.openscad.org/How-to-get-at-individual-children-tp11738p11752.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

That's an interesting idea! I just tried this... module segment(i, step, last) { rotate([0,0,i]) translate([10,0,0]) cylinder(); if (i < last) segment(i + step, step, last); } hull_join() { segment(0, 20, 120); } ... and I still end up with something that looks a like the right image. Something still seems to be making an implicit union. Is there some other approach that could avoid this? On Tue, Feb 24, 2015 at 2:27 PM, MichaelAtOz [via OpenSCAD] < ml-node+s1091067n11751h34@n5.nabble.com> wrote: > Have you considered recursion? (I haven't for your particular issue, brain > not awake yet) > Unless specifically shown otherwise above, my contribution is in the > Public Domain; To the extent possible under law, I have waived all > copyright and related or neighbouring rights to this work. This work is > published globally via the internet. :) > Inclusion of works of previous authors is not included in the above. > The *TPP* is no simple *“trade agreement.”* *Fight it!* > http://www.ourfairdeal.org/ > > > ------------------------------ > If you reply to this email, your message will be added to the discussion > below: > > http://forum.openscad.org/How-to-get-at-individual-children-tp11738p11751.html > To unsubscribe from How to get at individual children?, click here > <http://forum.openscad.org/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=11738&code=ZnJvbS1vcGVuc2NhZEB4ZW5vbWFjaGluYS5jb218MTE3Mzh8MjA2MDM4NDcyNA==> > . > NAML > <http://forum.openscad.org/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> > -- View this message in context: http://forum.openscad.org/How-to-get-at-individual-children-tp11738p11752.html Sent from the OpenSCAD mailing list archive at Nabble.com.
CL
Chow Loong Jin
Wed, Feb 25, 2015 3:07 AM

On Tue, Feb 24, 2015 at 04:35:30PM -0700, xenomachina wrote:

That's an interesting idea!

I just tried this...

 module segment(i, step, last) {
     rotate([0,0,i]) translate([10,0,0]) cylinder();
     if (i < last) segment(i + step, step, last);
 }

 hull_join() {
     segment(0, 20, 120);
 }

... and I still end up with something that looks a like the right image.

Something still seems to be making an implicit union. Is there some other
approach that could avoid this?

This doesn't work with arbitrary 3D objects, but will do what you want from one
child and a series of transformations:


use <scad-utils/transformations.scad>

module hull_join (transformations)
{
for (i = [0 : len (transformations) - 2])
hull () {
multmatrix (transformations[i])
children ();

    multmatrix (transformations[i + 1])
    children ();
}

}

hull_join ([
for (i = [0 : 20 : 120])
rotation ([0, 0, i]) *
translation ([10, 0, 0])
])
cylinder (d = 1, h = 20);

--
Kind regards,
Loong Jin

On Tue, Feb 24, 2015 at 04:35:30PM -0700, xenomachina wrote: > That's an interesting idea! > > I just tried this... > > module segment(i, step, last) { > rotate([0,0,i]) translate([10,0,0]) cylinder(); > if (i < last) segment(i + step, step, last); > } > > hull_join() { > segment(0, 20, 120); > } > > ... and I still end up with something that looks a like the right image. > > Something still seems to be making an implicit union. Is there some other > approach that could avoid this? This doesn't work with arbitrary 3D objects, but will do what you want from one child and a series of transformations: ------------- use <scad-utils/transformations.scad> module hull_join (transformations) { for (i = [0 : len (transformations) - 2]) hull () { multmatrix (transformations[i]) children (); multmatrix (transformations[i + 1]) children (); } } hull_join ([ for (i = [0 : 20 : 120]) rotation ([0, 0, i]) * translation ([10, 0, 0]) ]) cylinder (d = 1, h = 20); ------------- -- Kind regards, Loong Jin
CL
Chow Loong Jin
Wed, Feb 25, 2015 3:10 AM

Also worth looking at is generalized extrusion along path:

--
Kind regards,
Loong Jin

Also worth looking at is generalized extrusion along path: - https://github.com/openscad/openscad/issues/114 - https://github.com/openscad/list-comprehension-demos -- Kind regards, Loong Jin