The problem:
Idea:
State of the implementation:
Example part for testing: simply a cube:
module MyPart() {
translate( [ -50, 0, 0 ] ) {
cube( [ 100, 100, 5 ] );
}
}
Now I’m applying one of my operators (it creates a comb-like join):
Combs() {
MyPart();
}
and I get a left and a right part, split by the x=0 plane, with some offset, and using a “comb” pattern to connect the left and the right part.
So far so good. But my implementation is not as neat as I would like. If you look at the Combs module: https://github.com/jernst/openscad-cuts/blob/master/cuts/comb.scad , you see that I am repeating the two “cube” statements for both the Right and the Left part.
module Combs( … ) {
Right( ... ) {
cube( [ insert+play, step+2*play, height ] );
cube( [ insert-play, step-2*play, height ] );
children();
};
…
Left( … ) {
cube( [ insert+play, step+2*play, height ] );
cube( [ insert-play, step-2*play, height ] );
children();
}
}
These three items: two cubes and children() are passed to the Left and the Right module, which extract them:
I was thinking I should be able to do something like this, declaring the two cubes only once and reusing them via children():
module Combs2( ... ) {
LeftRight( ... ) {
cube( [ insert+play, step+2*play, height ] );
cube( [ insert-play, step-2*play, height ] );
children();
};
};
module LeftRight( ... ) {
translate( [ apart, 0, 0 ] )
Right( ... )
children();
translate( [ -apart, 0, 0 ] )
Left( ... )
children();
};
but somehow the children() aren’t making it down over multiple levels.
What am I doing wrong?
Thanks,
Johannes.
https://www.thingiverse.com/thing:35834 ?
On 3/28/2019 6:30 AM, Johannes Ernst wrote:
The problem:
Idea:
State of the implementation:
Example part for testing: simply a cube:
module MyPart() {
translate( [ -50, 0, 0 ] ) {
cube( [ 100, 100, 5 ] );
}
}
Now I’m applying one of my operators (it creates a comb-like join):
Combs() {
MyPart();
}
and I get a left and a right part, split by the x=0 plane, with some offset, and using a “comb” pattern to connect the left and the right part.
So far so good. But my implementation is not as neat as I would like. If you look at the Combs module: https://github.com/jernst/openscad-cuts/blob/master/cuts/comb.scad , you see that I am repeating the two “cube” statements for both the Right and the Left part.
module Combs( … ) {
Right( ... ) {
cube( [ insert+play, step+2*play, height ] );
cube( [ insert-play, step-2*play, height ] );
children();
};
…
Left( … ) {
cube( [ insert+play, step+2*play, height ] );
cube( [ insert-play, step-2*play, height ] );
children();
}
}
These three items: two cubes and children() are passed to the Left and the Right module, which extract them:
I was thinking I should be able to do something like this, declaring the two cubes only once and reusing them via children():
module Combs2( ... ) {
LeftRight( ... ) {
cube( [ insert+play, step+2*play, height ] );
cube( [ insert-play, step-2*play, height ] );
children();
};
};
module LeftRight( ... ) {
translate( [ apart, 0, 0 ] )
Right( ... )
children();
translate( [ -apart, 0, 0 ] )
Left( ... )
children();
};
but somehow the children() aren’t making it down over multiple levels.
What am I doing wrong?
Thanks,
Johannes.
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
On Mar 28, 2019, at 4:40, Tim V. Shaporev tim.shaporev@auriga.ru wrote:
This is cool, and might solve my bigger problem better than I would have. Thanks!
However, my post was mostly about: how do I get OpenSCAD to do what I want it to do? How do I correctly pass children() over multiple levels?
Cheers,
Johannes.
What you're trying to do is (currently) impossible. Modules can return only
one child up to the calling module. It will be the union of all the
children if you don't use some other operator to combine them in a different
way.
--
Sent from: http://forum.openscad.org/
Darn!
(Perhaps the operator idea could benefit from some inspiration from some other (software) languages that have comparable notions. None have something like children() that I’m aware of…)
P.S. Thanks.
On Mar 28, 2019, at 13:43, adrianv avm4@cornell.edu wrote:
What you're trying to do is (currently) impossible. Modules can return only
one child up to the calling module. It will be the union of all the
children if you don't use some other operator to combine them in a different
way.
--
Sent from: http://forum.openscad.org/
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
On 3/28/2019 1:43 PM, adrianv wrote:
What you're trying to do is (currently) impossible. Modules can return only
one child up to the calling module. It will be the union of all the
children if you don't use some other operator to combine them in a different
way.
And in particular this seems to apply to the children() module-like-thing.
module i() {
intersection()
children();
}
i() {
cube(1,center=true);
sphere(.6,$fn=20);
}
yields the union of the cube and the sphere, not the intersection.
However, going back to the original problem:
* child 1 and child 2 are used as the pattern for the cut
* child 3 is the part to be cut
...
module Combs2( ... ) {
LeftRight( ... ) {
cube( [ insert+play, step+2play, height ] );
cube( [ insert-play, step-2play, height ] );
children();
};
};
module LeftRight( ... ) {
translate( [ apart, 0, 0 ] )
Right( ... )
children();
translate( [ -apart, 0, 0 ] )
Left( ... )
children();
};
The problem is that children() is implicitly unioning the children. But
if you pass them separately it should be OK:
module Combs2( ... ) {
LeftRight( ... ) {
cube( [ insert+play, step+2*play, height ] );
cube( [ insert-play, step-2*play, height ] );
children();
};
};
module LeftRight( ... ) {
translate( [ apart, 0, 0 ] )
Right( ... ) {
children(0);
children(1);
children(2);
}
translate( [ -apart, 0, 0 ] )
Left( ... ) {
children(0);
children(1);
children(2);
}
};
And indeed my intersection example works right if I do it like so:
module i() {
intersection() {
children(0);
children(1);
}
}
i() {
cube(1,center=true);
sphere(.6,$fn=20);
}
Note that if you want to collect up all of the children after the first
two you can use children([2:$children-1]). (But they'll be implicitly
unioned.)
I don’t know if it’s RC4 or the result of my recent upgrade to macOS 10.14.4 but even the simplest program using the debug modifier ‘#’ now displays the selected object in a flickering pink.
I don’t know if it's a feature or a bug, and perhaps only relevant to the Mac.
Anyway, here’s a short program that reveals the problem … at least on my machine… just wondering if anyone else is experiencing it as well…
difference() {
cube([22,14,4], center = true);
cube([14, 7, 8], center = true);
}
NOTE: the window has to be in focus for the flicker to reveal itself.