discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Re: [OpenSCAD] combine a union child and a difference child inoneobject.

L
Leef_me
Tue, Dec 1, 2015 12:54 AM

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

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
N
Neon22
Tue, Dec 1, 2015 1:25 AM

How about this:

cyl_res = 16;

module wire()  {
difference() {
// outer block
cube(size=[5,5,5], center=true);
// subtract this
children(0);
}
}

wire() cylinder(d=1.5, h=7, center=true, $fn=cyl_res);
cylinder(d=1, h=15, center=true, $fn=cyl_res);

--
View this message in context: http://forum.openscad.org/combine-a-union-child-and-a-difference-child-in-one-object-tp14834p14854.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

How about this: cyl_res = 16; module wire() { difference() { // outer block cube(size=[5,5,5], center=true); // subtract this children(0); } } wire() cylinder(d=1.5, h=7, center=true, $fn=cyl_res); cylinder(d=1, h=15, center=true, $fn=cyl_res); -- View this message in context: http://forum.openscad.org/combine-a-union-child-and-a-difference-child-in-one-object-tp14834p14854.html Sent from the OpenSCAD mailing list archive at Nabble.com.
NH
nop head
Tue, Dec 1, 2015 9:43 AM

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 nop.head@gmail.com
Sent: Monday, November 30, 2015 4:22 PM
To: OpenSCAD general discussion discuss@lists.openscad.org
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

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 <nop.head@gmail.com> > *Sent:* Monday, November 30, 2015 4:22 PM > *To:* OpenSCAD general discussion <discuss@lists.openscad.org> > *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 > >
C
ctchin
Tue, Dec 1, 2015 11:02 AM

nophead wrote

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.

This is not a programming issue but a matter of organization.  Those are not
two completely different things.  It makes perfect sense to throw several
highly
related things (with inter-related dimensions, e.g.) into a module and pass
sensible arguments to it to retrieve various part of that thing or variant
incarnations of the same thing.

However I would not use numeric arguments.  Rather use strings:

You can even write a more elaborate if () ... else ... statements using
search()
that would allow the calling routine to pass a vector of strings, so that
any
number of parts can be retrieved by a single call e.g.

--
View this message in context: http://forum.openscad.org/combine-a-union-child-and-a-difference-child-in-one-object-tp14834p14864.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

nophead wrote > 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. This is not a programming issue but a matter of organization. Those are not two completely different things. It makes perfect sense to throw several highly related things (with inter-related dimensions, e.g.) into a module and pass sensible arguments to it to retrieve various part of that thing or variant incarnations of the same thing. However I would not use numeric arguments. Rather use strings: You can even write a more elaborate if () ... else ... statements using search() that would allow the calling routine to pass a vector of strings, so that any number of parts can be retrieved by a single call e.g. -- View this message in context: http://forum.openscad.org/combine-a-union-child-and-a-difference-child-in-one-object-tp14834p14864.html Sent from the OpenSCAD mailing list archive at Nabble.com.