I disagree with your comment that they are completely different things.
One encapsulates the other,
You notice that the code can be single lines; but I have only presented the simplest form for discussion.
I found this reference, but I'm working through it.
http://www.tridimake.com/2014/11/how-to-use-openscad-4-children-and.html
From: nop head
Sent: Tuesday, December 01, 2015 1:43 AM
To: OpenSCAD general discussion
Subject: Re: [OpenSCAD] combine a union child and a difference childinoneobject.
Passing a parameter to a module to make it do two completely different things doesn't make sense from a programming point of view. It is better to stop pretending it is a single thing and make two modules: wire_inner() and wire_outer(). That is a lot more descriptive than wire(which=2) and wire(which=-1) and since they can be single line modules it is actually less code.
module wire_inner()cylinder(d = 1, h = 15, center = true);
module wire_outer()cylinder(d = 1.5, h = 7, center = true);
$fn=16;
difference() {
cube([5, 5, 5], center = true);
wire_outer(); // part A
};
wire_inner(); // part B
It is more readable but it still doesn't get around the fact you can't have negative objects outside of a difference.
You could make a module that does both an add and a subtract but it makes these code more obscure.
module add_and_subtract()
union() {
difference() {
children(0);
children(1);
}
children(2);
}
$fn=16;
add_and_subtract() {
cube([5, 5, 5], center = true);
wire_outer();
wire_inner();
}
And you could to a truly horrible hack like this: -
module wire()
if($negative)
wire_outer();
else
wire_inner();
module add_and_subtract()
union() {
difference() {
children(0);
$negative = true;
children(1);
}
$negative = false;
children(1);
}
$fn=16;
add_and_subtract() {
cube([5, 5, 5], center = true);
wire();
}
But I think it is just obscuration.
On 1 December 2015 at 00:54, Leef_me Leef_me@cox.net wrote:
Here is a new version that does something of what I want.
$fn=16;
difference()
{
cube([5,5,5], center=true);
wire(which=2); // part A
};
wire(which=-1); // part B
module wire(which=1)
{
if (which==-1)
cylinder(d=1, h=15, center=true); // part B
else
#cylinder(d=1.5, h=7, center=true); // part A
};
This page refers to children, but I don't see how to change the module to use children(0) or children(1)
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/The_OpenSCAD_Language#Object_modules
From: nop head
Sent: Monday, November 30, 2015 4:22 PM
To: OpenSCAD general discussion
Subject: Re: [OpenSCAD] combine a union child and a difference child inoneobject.
No you can't do that in one operation in OpenScad. You need to subtract the hole and add the rod. You could subtract a tube, which would leave a hole with a rod in it but it couldn't protrude out of the cube without adding it.
On 1 December 2015 at 00:08, Leef_me Leef_me@cox.net wrote:
You have all the essentially information.
The cube has a cylindrical hole cut vertically through it.
Inside this is a thinner rod.
They are not connected together in any place.
We can't work out what sort of object you are trying to make.
I want the "cylindrical hole" to be in the same module as the "thinner rod".
Wherever the "thinner rod" is placed, the "cylindrical hole" follows.
If I build a union of all the "thinner rods", their companion holes are cut from some shape that I specify.
--------------------------------------------------
From: "Neon22" <mschafer@wireframe.biz>
Sent: Monday, November 30, 2015 2:32 PM
To: <discuss@lists.openscad.org>
Subject: Re: [OpenSCAD] combine a union child and a difference child in oneobject.
The cube has a cylindrical hole cut vertically through it.
Inside this is a thinner rod.
They are not connected together in any place.
We can't work out what sort of object you are trying to make.
You could add a flattened cube at the bottom and thereby make a mold kind-of
object to perhaps pour goop into to make tubes, but not sure what this
object is trying to acheive so not sure how to answer your question.
--
View this message in context: http://forum.openscad.org/combine-a-union-child-and-a-difference-child-in-one-object-tp14834p14846.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
_______________________________________________
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org