discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

difference() is not working as expected

F
fpa512@email.com
Wed, Nov 20, 2024 3:25 PM

Hi’yall

As rookie, I have s small problem with a script when creating a cube with some cut outs.

I have the following code:

// create switch housing

w = 30;        // width of cube

h =  40;        // height of cube

hd = 16;        // hole diameter for switch

wt = 2;        // wall-thickness

difference () {

 cube(\[w, w, h\], false);

     translate ( \[wt, wt, 0\] ) cube(\[w-wt\*2, w-wt\*2, h-wt\], false);

     translate ( \[w/2, w/2, h-0.001\]) cylinder ($fn=200,h=wt\*2, d = hd);

 };

I’m having a problem with the 2nd ‘translate’.

It supposed to cut out the opening for the switch in the housing.

What am I doing wrong here?

Any help is much appreciate.

TIA

Version: OpenSCAD version 2024.08.18.ai20248 (git a16ca2a67)

on Linux Mint v22.3

Hi’yall As rookie, I have s small problem with a script when creating a cube with some cut outs. I have the following code: > // create switch housing > > w = 30; // width of cube > > h = 40; // height of cube > > hd = 16; // hole diameter for switch > > wt = 2; // wall-thickness > > difference () { > > cube(\[w, w, h\], false); > > translate ( \[wt, wt, 0\] ) cube(\[w-wt\*2, w-wt\*2, h-wt\], false); > > translate ( \[w/2, w/2, h-0.001\]) cylinder ($fn=200,h=wt\*2, d = hd); > > }; I’m having a problem with the 2nd ‘translate’. It supposed to cut out the opening for the switch in the housing. What am I doing wrong here? Any help is much appreciate. TIA Version: OpenSCAD **version 2024.08.18.ai20248 (git a16ca2a67)** on Linux Mint v22.3
NH
nop head
Wed, Nov 20, 2024 3:34 PM

Your cylinder is only 0.001 below the top surface. It should be slightly
less than wt below. Try this:
difference () {

cube([w, w, h], false);

translate ( [wt, wt, -0.001] ) cube([w-wt2, w-wt2, h-wt + 0.001], false);

translate ( [w/2, w/2, h-wt-0.002]) cylinder ($fn=200,h=wt*2, d = hd);

};

On Wed, 20 Nov 2024 at 15:25, fpa512--- via Discuss <
discuss@lists.openscad.org> wrote:

Hi’yall

As rookie, I have s small problem with a script when creating a cube with
some cut outs.

I have the following code:

// create switch housing

w = 30; // width of cube

h = 40; // height of cube

hd = 16; // hole diameter for switch

wt = 2; // wall-thickness

difference () {

cube([w, w, h], false);

translate ( [wt, wt, 0] ) cube([w-wt2, w-wt2, h-wt], false);

translate ( [w/2, w/2, h-0.001]) cylinder ($fn=200,h=wt*2, d = hd);

};

I’m having a problem with the 2nd ‘translate’.

It supposed to cut out the opening for the switch in the housing.

What am I doing wrong here?

Any help is much appreciate.

TIA

Version: OpenSCAD version 2024.08.18.ai20248 (git a16ca2a67)

on Linux Mint v22.3


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

Your cylinder is only 0.001 below the top surface. It should be slightly less than wt below. Try this: difference () { cube([w, w, h], false); translate ( [wt, wt, -0.001] ) cube([w-wt*2, w-wt*2, h-wt + 0.001], false); translate ( [w/2, w/2, h-wt-0.002]) cylinder ($fn=200,h=wt*2, d = hd); }; On Wed, 20 Nov 2024 at 15:25, fpa512--- via Discuss < discuss@lists.openscad.org> wrote: > Hi’yall > > As rookie, I have s small problem with a script when creating a cube with > some cut outs. > > I have the following code: > > // create switch housing > > w = 30; // width of cube > > h = 40; // height of cube > > hd = 16; // hole diameter for switch > > wt = 2; // wall-thickness > > difference () { > > cube([w, w, h], false); > > translate ( [wt, wt, 0] ) cube([w-wt*2, w-wt*2, h-wt], false); > > translate ( [w/2, w/2, h-0.001]) cylinder ($fn=200,h=wt*2, d = hd); > > }; > > I’m having a problem with the 2nd ‘translate’. > > It supposed to cut out the opening for the switch in the housing. > > What am I doing wrong here? > > Any help is much appreciate. > > TIA > > > Version: OpenSCAD *version 2024.08.18.ai20248 (git a16ca2a67)* > > on Linux Mint v22.3 > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
TA
Todd Allen
Wed, Nov 20, 2024 3:37 PM

You can use the modifier character # with objects being differenced away to
visualize them and confirm they are aligned as expected.  You also want to
slightly oversize objects for differences and unions to ensure they fully
cut through or fully overlap.

On Wed, Nov 20, 2024 at 9:26 AM fpa512--- via Discuss <
discuss@lists.openscad.org> wrote:

Hi’yall

As rookie, I have s small problem with a script when creating a cube with
some cut outs.

I have the following code:

// create switch housing

w = 30; // width of cube

h = 40; // height of cube

hd = 16; // hole diameter for switch

wt = 2; // wall-thickness

difference () {

cube([w, w, h], false);

translate ( [wt, wt, 0] ) cube([w-wt2, w-wt2, h-wt], false);

translate ( [w/2, w/2, h-0.001]) cylinder ($fn=200,h=wt*2, d = hd);

};

I’m having a problem with the 2nd ‘translate’.

It supposed to cut out the opening for the switch in the housing.

What am I doing wrong here?

Any help is much appreciate.

TIA

Version: OpenSCAD version 2024.08.18.ai20248 (git a16ca2a67)

on Linux Mint v22.3


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

You can use the modifier character # with objects being differenced away to visualize them and confirm they are aligned as expected. You also want to slightly oversize objects for differences and unions to ensure they fully cut through or fully overlap. On Wed, Nov 20, 2024 at 9:26 AM fpa512--- via Discuss < discuss@lists.openscad.org> wrote: > Hi’yall > > As rookie, I have s small problem with a script when creating a cube with > some cut outs. > > I have the following code: > > // create switch housing > > w = 30; // width of cube > > h = 40; // height of cube > > hd = 16; // hole diameter for switch > > wt = 2; // wall-thickness > > difference () { > > cube([w, w, h], false); > > translate ( [wt, wt, 0] ) cube([w-wt*2, w-wt*2, h-wt], false); > > translate ( [w/2, w/2, h-0.001]) cylinder ($fn=200,h=wt*2, d = hd); > > }; > > I’m having a problem with the 2nd ‘translate’. > > It supposed to cut out the opening for the switch in the housing. > > What am I doing wrong here? > > Any help is much appreciate. > > TIA > > > Version: OpenSCAD *version 2024.08.18.ai20248 (git a16ca2a67)* > > on Linux Mint v22.3 > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
RW
Raymond West
Wed, Nov 20, 2024 3:58 PM

For differences, it can help to use # in f5 rendering,to see where the
'holes' are. A simple technique, is to multiply the height by three and
move down by 1, as the second line  shown below. It can avoid errors by
'pushing the holes through much further than necessary', so to speak.

 //# translate ( [w/2, w/2, 0]) cylinder ($fn=200,h=h2, d = hd);
  # translate([w/2,w/2,h-wt]) cylinder ($fn=200,h=wt
3,d=hd);

On 20/11/2024 15:34, nop head via Discuss wrote:

Your cylinder is only 0.001 below the top surface. It should be
slightly less than wt below. Try this:
difference () {

cube([w, w, h], false);

translate ( [wt, wt, -0.001] ) cube([w-wt2, w-wt2, h-wt + 0.001],
false);

translate ( [w/2, w/2, h-wt-0.002]) cylinder ($fn=200,h=wt*2, d = hd);

};

On Wed, 20 Nov 2024 at 15:25, fpa512--- via Discuss
discuss@lists.openscad.org wrote:

 Hi’yall

 As rookie, I have s small problem with a script when creating a
 cube with some cut outs.

 I have the following code:

     // create switch housing

     w = 30; // width of cube

     h = 40; // height of cube

     hd = 16; // hole diameter for switch

     wt = 2; // wall-thickness

     difference () {

     cube([w, w, h], false);

     translate ( [wt, wt, 0] ) cube([w-wt*2, w-wt*2, h-wt], false);

     translate ( [w/2, w/2, h-0.001]) cylinder ($fn=200,h=wt*2, d =
     hd);

     };

 I’m having a problem with the 2nd ‘translate’.

 It supposed to cut out the opening for the switch in the housing.

 What am I doing wrong here?

 Any help is much appreciate.

 TIA


 Version: OpenSCAD *version 2024.08.18.ai20248 (git a16ca2a67)*

 on Linux Mint v22.3

 _______________________________________________
 OpenSCAD mailing list
 To unsubscribe send an email to discuss-leave@lists.openscad.org

OpenSCAD mailing list
To unsubscribe send an email todiscuss-leave@lists.openscad.org

For differences, it can help to use # in f5 rendering,to see where the 'holes' are. A simple technique, is to multiply the height by three and move down by 1, as the second line  shown below. It can avoid errors by 'pushing the holes through much further than necessary', so to speak.  //# translate ( [w/2, w/2, 0]) cylinder ($fn=200,h=h*2, d = hd);   # translate([w/2,w/2,h-wt]) cylinder ($fn=200,h=wt*3,d=hd); On 20/11/2024 15:34, nop head via Discuss wrote: > Your cylinder is only 0.001 below the top surface. It should be > slightly less than wt below. Try this: > difference () { > > cube([w, w, h], false); > > translate ( [wt, wt, -0.001] ) cube([w-wt*2, w-wt*2, h-wt + 0.001], > false); > > translate ( [w/2, w/2, h-wt-0.002]) cylinder ($fn=200,h=wt*2, d = hd); > > }; > > > On Wed, 20 Nov 2024 at 15:25, fpa512--- via Discuss > <discuss@lists.openscad.org> wrote: > > Hi’yall > > As rookie, I have s small problem with a script when creating a > cube with some cut outs. > > I have the following code: > > // create switch housing > > w = 30; // width of cube > > h = 40; // height of cube > > hd = 16; // hole diameter for switch > > wt = 2; // wall-thickness > > difference () { > > cube([w, w, h], false); > > translate ( [wt, wt, 0] ) cube([w-wt*2, w-wt*2, h-wt], false); > > translate ( [w/2, w/2, h-0.001]) cylinder ($fn=200,h=wt*2, d = > hd); > > }; > > I’m having a problem with the 2nd ‘translate’. > > It supposed to cut out the opening for the switch in the housing. > > What am I doing wrong here? > > Any help is much appreciate. > > TIA > > > Version: OpenSCAD *version 2024.08.18.ai20248 (git a16ca2a67)* > > on Linux Mint v22.3 > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org > > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email todiscuss-leave@lists.openscad.org
ME
Mark Erbaugh
Wed, Nov 20, 2024 5:10 PM

The cut out cylinder is positioned on top of the cube, so it is not cutting anything.  Change the last statement to:

translate ( [w/2, w/2, h-wt-0.001]) cylinder ($fn=200,h=wt*2, d = hd);

Note that it is lowering the translation by the wall thickness so the bottom of the cylinder is at the bottom of the top wall.

Mark

On Nov 20, 2024, at 10:25 AM, fpa512--- via Discuss discuss@lists.openscad.org wrote:

Hi’yall

As rookie, I have s small problem with a script when creating a cube with some cut outs.

I have the following code:

// create switch housing

w = 30; // width of cube

h = 40; // height of cube

hd = 16; // hole diameter for switch

wt = 2; // wall-thickness

difference () {

cube([w, w, h], false);

translate ( [wt, wt, 0] ) cube([w-wt2, w-wt2, h-wt], false);

translate ( [w/2, w/2, h-0.001]) cylinder ($fn=200,h=wt*2, d = hd);

};

I’m having a problem with the 2nd ‘translate’.

It supposed to cut out the opening for the switch in the housing.

What am I doing wrong here?

Any help is much appreciate.

TIA

Version: OpenSCAD version 2024.08.18.ai20248 (git a16ca2a67)

on Linux Mint v22.3


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

The cut out cylinder is positioned on top of the cube, so it is not cutting anything. Change the last statement to: translate ( [w/2, w/2, h-wt-0.001]) cylinder ($fn=200,h=wt*2, d = hd); Note that it is lowering the translation by the wall thickness so the bottom of the cylinder is at the bottom of the top wall. Mark > On Nov 20, 2024, at 10:25 AM, fpa512--- via Discuss <discuss@lists.openscad.org> wrote: > > Hi’yall > > As rookie, I have s small problem with a script when creating a cube with some cut outs. > > I have the following code: > > // create switch housing > > w = 30; // width of cube > > h = 40; // height of cube > > hd = 16; // hole diameter for switch > > wt = 2; // wall-thickness > > difference () { > > cube([w, w, h], false); > > translate ( [wt, wt, 0] ) cube([w-wt*2, w-wt*2, h-wt], false); > > translate ( [w/2, w/2, h-0.001]) cylinder ($fn=200,h=wt*2, d = hd); > > }; > > I’m having a problem with the 2nd ‘translate’. > > It supposed to cut out the opening for the switch in the housing. > > What am I doing wrong here? > > Any help is much appreciate. > > TIA > > > > Version: OpenSCAD version 2024.08.18.ai20248 (git a16ca2a67) > > on Linux Mint v22.3 > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org
F
FPA
Wed, Nov 20, 2024 7:30 PM

That works beautifully. Thanks to all.

Fred

On 2024-11-20 12:10, Mark Erbaugh via Discuss wrote:

The cut out cylinder is positioned on top of the cube, so it is not
cutting anything.  Change the last statement to:

translate ( [w/2, w/2, h-wt-0.001]) cylinder ($fn=200,h=wt*2, d = hd);

Note that it is lowering the translation by the wall thickness so the
bottom of the cylinder is at the bottom of the top wall.

Mark

On Nov 20, 2024, at 10:25 AM, fpa512--- via Discuss
discuss@lists.openscad.org wrote:

Hi’yall

As rookie, I have s small problem with a script when creating a cube
with some cut outs.

I have the following code:

 // create switch housing

 w = 30; // width of cube

 h = 40; // height of cube

 hd = 16; // hole diameter for switch

 wt = 2; // wall-thickness

 difference () {

 cube([w, w, h], false);

 translate ( [wt, wt, 0] ) cube([w-wt*2, w-wt*2, h-wt], false);

 translate ( [w/2, w/2, h-0.001]) cylinder ($fn=200,h=wt*2, d = hd);

 };

I’m having a problem with the 2nd ‘translate’.

It supposed to cut out the opening for the switch in the housing.

What am I doing wrong here?

Any help is much appreciate.

TIA

Version: OpenSCAD version 2024.08.18.ai20248 (git a16ca2a67)

on Linux Mint v22.3


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org


OpenSCAD mailing list
To unsubscribe send an email todiscuss-leave@lists.openscad.org

That works beautifully. Thanks to all. Fred On 2024-11-20 12:10, Mark Erbaugh via Discuss wrote: > The cut out cylinder is positioned on top of the cube, so it is not > cutting anything.  Change the last statement to: > > translate ( [w/2, w/2, h-wt-0.001]) cylinder ($fn=200,h=wt*2, d = hd); > > Note that it is lowering the translation by the wall thickness so the > bottom of the cylinder is at the bottom of the top wall. > > Mark > > > >> On Nov 20, 2024, at 10:25 AM, fpa512--- via Discuss >> <discuss@lists.openscad.org> wrote: >> >> Hi’yall >> >> As rookie, I have s small problem with a script when creating a cube >> with some cut outs. >> >> I have the following code: >> >> // create switch housing >> >> w = 30; // width of cube >> >> h = 40; // height of cube >> >> hd = 16; // hole diameter for switch >> >> wt = 2; // wall-thickness >> >> difference () { >> >> cube([w, w, h], false); >> >> translate ( [wt, wt, 0] ) cube([w-wt*2, w-wt*2, h-wt], false); >> >> translate ( [w/2, w/2, h-0.001]) cylinder ($fn=200,h=wt*2, d = hd); >> >> }; >> >> I’m having a problem with the 2nd ‘translate’. >> >> It supposed to cut out the opening for the switch in the housing. >> >> What am I doing wrong here? >> >> Any help is much appreciate. >> >> TIA >> >> >> Version: OpenSCAD *version 2024.08.18.ai20248 (git a16ca2a67)* >> >> on Linux Mint v22.3 >> >> _______________________________________________ >> OpenSCAD mailing list >> To unsubscribe send an email to discuss-leave@lists.openscad.org > > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email todiscuss-leave@lists.openscad.org
HW
Harvey white
Wed, Nov 20, 2024 7:59 PM

There's a further trick you can use:

take the following code as an example.

            translate([0,0,0])
            {
                difference()
                {
                    union()
                    {
                        color ("purple") cube([25.4, 15.88, 1],center =
true);
color("white")translate([0,-6,.5])rotate([0,0,0])linear_extrude(0.2)text("MPU9250",size=2,halign
= "center",valign = "center");
translate([11.3,4.2,0])rotate([0,0,90])index_mark();
                    }
                    union()
                    {
                        translate([10,-6,-3]) cylinder(d = 3, h = 10);
                        translate([-10,-6,-3]) cylinder(d = 3, h = 10);
                    }
                }
            }

The translate part simply allows you to offset the entire object.  Since
this is a difference, the unions make it clear (to you) what is being
subtracted from what.

The trick is that with difference on a separate line, commenting it out
simply renders the negative objects as positive, and allows you to see
exactly where the holes will be (easiest when the base object is
transparent).

Easy change to and from.

Harvey

On 11/20/2024 2:30 PM, FPA via Discuss wrote:

That works beautifully. Thanks to all.

Fred

On 2024-11-20 12:10, Mark Erbaugh via Discuss wrote:

The cut out cylinder is positioned on top of the cube, so it is not
cutting anything.  Change the last statement to:

translate ( [w/2, w/2, h-wt-0.001]) cylinder ($fn=200,h=wt*2, d = hd);

Note that it is lowering the translation by the wall thickness so the
bottom of the cylinder is at the bottom of the top wall.

Mark

On Nov 20, 2024, at 10:25 AM, fpa512--- via Discuss
discuss@lists.openscad.org wrote:

Hi’yall

As rookie, I have s small problem with a script when creating a cube
with some cut outs.

I have the following code:

 // create switch housing

 w = 30; // width of cube

 h = 40; // height of cube

 hd = 16; // hole diameter for switch

 wt = 2; // wall-thickness

 difference () {

 cube([w, w, h], false);

 translate ( [wt, wt, 0] ) cube([w-wt*2, w-wt*2, h-wt], false);

 translate ( [w/2, w/2, h-0.001]) cylinder ($fn=200,h=wt*2, d = hd);

 };

I’m having a problem with the 2nd ‘translate’.

It supposed to cut out the opening for the switch in the housing.

What am I doing wrong here?

Any help is much appreciate.

TIA

Version: OpenSCAD version 2024.08.18.ai20248 (git a16ca2a67)

on Linux Mint v22.3


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org


OpenSCAD mailing list
To unsubscribe send an email todiscuss-leave@lists.openscad.org


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

There's a further trick you can use: take the following code as an example.             translate([0,0,0])             {                 difference()                 {                     union()                     {                         color ("purple") cube([25.4, 15.88, 1],center = true); color("white")translate([0,-6,.5])rotate([0,0,0])linear_extrude(0.2)text("MPU9250",size=2,halign = "center",valign = "center"); translate([11.3,4.2,0])rotate([0,0,90])index_mark();                     }                     union()                     {                         translate([10,-6,-3]) cylinder(d = 3, h = 10);                         translate([-10,-6,-3]) cylinder(d = 3, h = 10);                     }                 }             } The translate part simply allows you to offset the entire object.  Since this is a difference, the unions make it clear (to you) what is being subtracted from what. The trick is that with difference on a separate line, commenting it out simply renders the negative objects as positive, and allows you to see exactly where the holes will be (easiest when the base object is transparent). Easy change to and from. Harvey On 11/20/2024 2:30 PM, FPA via Discuss wrote: > > That works beautifully. Thanks to all. > > Fred > > On 2024-11-20 12:10, Mark Erbaugh via Discuss wrote: >> The cut out cylinder is positioned on top of the cube, so it is not >> cutting anything.  Change the last statement to: >> >> translate ( [w/2, w/2, h-wt-0.001]) cylinder ($fn=200,h=wt*2, d = hd); >> >> Note that it is lowering the translation by the wall thickness so the >> bottom of the cylinder is at the bottom of the top wall. >> >> Mark >> >> >> >>> On Nov 20, 2024, at 10:25 AM, fpa512--- via Discuss >>> <discuss@lists.openscad.org> wrote: >>> >>> Hi’yall >>> >>> As rookie, I have s small problem with a script when creating a cube >>> with some cut outs. >>> >>> I have the following code: >>> >>> // create switch housing >>> >>> w = 30; // width of cube >>> >>> h = 40; // height of cube >>> >>> hd = 16; // hole diameter for switch >>> >>> wt = 2; // wall-thickness >>> >>> difference () { >>> >>> cube([w, w, h], false); >>> >>> translate ( [wt, wt, 0] ) cube([w-wt*2, w-wt*2, h-wt], false); >>> >>> translate ( [w/2, w/2, h-0.001]) cylinder ($fn=200,h=wt*2, d = hd); >>> >>> }; >>> >>> I’m having a problem with the 2nd ‘translate’. >>> >>> It supposed to cut out the opening for the switch in the housing. >>> >>> What am I doing wrong here? >>> >>> Any help is much appreciate. >>> >>> TIA >>> >>> >>> Version: OpenSCAD *version 2024.08.18.ai20248 (git a16ca2a67)* >>> >>> on Linux Mint v22.3 >>> >>> _______________________________________________ >>> OpenSCAD mailing list >>> To unsubscribe send an email to discuss-leave@lists.openscad.org >> >> >> _______________________________________________ >> OpenSCAD mailing list >> To unsubscribe send an email todiscuss-leave@lists.openscad.org > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org
M
mikeonenine@web.de
Wed, Nov 20, 2024 11:47 PM

FPA wrote:

That works beautifully. Thanks to all.

Fred

On 2024-11-20 12:10, Mark Erbaugh via Discuss wrote:

The cut out cylinder is positioned on top of the cube, so it is not
cutting anything.  Change the last statement to:

translate ( [w/2, w/2, h-wt-0.001]) cylinder ($fn=200,h=wt*2, d = hd);

Note that it is lowering the translation by the wall thickness so the
bottom of the cylinder is at the bottom of the top wall.

Mark

On Nov 20, 2024, at 10:25 AM, fpa512--- via Discuss
discuss@lists.openscad.org wrote:

Hi’yall

As rookie, I have s small problem with a script when creating a cube
with some cut outs.

I have the following code:

// create switch housing

w = 30; // width of cube

h = 40; // height of cube

hd = 16; // hole diameter for switch

wt = 2; // wall-thickness

difference () {

cube([w, w, h], false);

translate ( [wt, wt, 0] ) cube([w-wt*2, w-wt*2, h-wt], false);

translate ( [w/2, w/2, h-0.001]) cylinder ($fn=200,h=wt*2, d = hd);

};

I’m having a problem with the 2nd ‘translate’.

It supposed to cut out the opening for the switch in the housing.

What am I doing wrong here?

Any help is much appreciate.

TIA

Version: OpenSCAD version 2024.08.18.ai20248 (git a16ca2a67)

on Linux Mint v22.3


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org


OpenSCAD mailing list
To unsubscribe send an email todiscuss-leave@lists.openscad.org

Another useful feature is center=true. It anchors objects in their centre, which simplifies things in most, but not all cases. I use it about 80% of the time. Regrettably, it’s not the default.

FPA wrote: > That works beautifully. Thanks to all. > > Fred > > On 2024-11-20 12:10, Mark Erbaugh via Discuss wrote: > > > The cut out cylinder is positioned on top of the cube, so it is not > > cutting anything.  Change the last statement to: > > > > translate ( \[w/2, w/2, h-wt-0.001\]) cylinder ($fn=200,h=wt\*2, d = hd); > > > > Note that it is lowering the translation by the wall thickness so the > > bottom of the cylinder is at the bottom of the top wall. > > > > Mark > > > > > On Nov 20, 2024, at 10:25 AM, fpa512--- via Discuss > > > [discuss@lists.openscad.org](mailto:discuss@lists.openscad.org) wrote: > > > > > > Hi’yall > > > > > > As rookie, I have s small problem with a script when creating a cube > > > with some cut outs. > > > > > > I have the following code: > > > > > > ``` > > > // create switch housing > > > > > > w = 30; // width of cube > > > > > > h = 40; // height of cube > > > > > > hd = 16; // hole diameter for switch > > > > > > wt = 2; // wall-thickness > > > > > > difference () { > > > > > > cube([w, w, h], false); > > > > > > translate ( [wt, wt, 0] ) cube([w-wt*2, w-wt*2, h-wt], false); > > > > > > translate ( [w/2, w/2, h-0.001]) cylinder ($fn=200,h=wt*2, d = hd); > > > > > > }; > > > ``` > > > > > > I’m having a problem with the 2nd ‘translate’. > > > > > > It supposed to cut out the opening for the switch in the housing. > > > > > > What am I doing wrong here? > > > > > > Any help is much appreciate. > > > > > > TIA > > > > > > Version: OpenSCAD *version 2024.08.18.ai20248 (git a16ca2a67)* > > > > > > on Linux Mint v22.3 > > > > > > --- > > > > > > OpenSCAD mailing list > > > To unsubscribe send an email to discuss-leave@lists.openscad.org > > > > --- > > > > OpenSCAD mailing list > > To unsubscribe send an email todiscuss-leave@lists.openscad.org Another useful feature is center=true. It anchors objects in their centre, which simplifies things in most, but not all cases. I use it about 80% of the time. Regrettably, it’s not the default.
RW
Rogier Wolff
Thu, Nov 21, 2024 10:54 AM

On Wed, Nov 20, 2024 at 02:30:59PM -0500, FPA via Discuss wrote:

That works beautifully. Thanks to all.

Note that this has happend once or twice in the past that someone
tries do "difference" something and unexpectedly "nothing happens".

Openscad has a trick: Prefix the thing that's not working with # and
it will show up as a see-through pink object. Often you'll see what's
wrong immediately.

Roger. 

Fred

On 2024-11-20 12:10, Mark Erbaugh via Discuss wrote:

The cut out cylinder is positioned on top of the cube, so it is not
cutting anything.  Change the last statement to:

translate ( [w/2, w/2, h-wt-0.001]) cylinder ($fn=200,h=wt*2, d = hd);

Note that it is lowering the translation by the wall thickness so the
bottom of the cylinder is at the bottom of the top wall.

Mark

On Nov 20, 2024, at 10:25 AM, fpa512--- via Discuss
discuss@lists.openscad.org wrote:

Hi’yall

As rookie, I have s small problem with a script when creating a cube
with some cut outs.

I have the following code:

 // create switch housing

 w = 30; // width of cube

 h = 40; // height of cube

 hd = 16; // hole diameter for switch

 wt = 2; // wall-thickness

 difference () {

 cube([w, w, h], false);

 translate ( [wt, wt, 0] ) cube([w-wt*2, w-wt*2, h-wt], false);

 translate ( [w/2, w/2, h-0.001]) cylinder ($fn=200,h=wt*2, d = hd);

 };

I’m having a problem with the 2nd ‘translate’.

It supposed to cut out the opening for the switch in the housing.

What am I doing wrong here?

Any help is much appreciate.

TIA

Version: OpenSCAD version 2024.08.18.ai20248 (git a16ca2a67)

on Linux Mint v22.3


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org


OpenSCAD mailing list
To unsubscribe send an email todiscuss-leave@lists.openscad.org


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

--
** R.E.Wolff@BitWizard.nl ** https://www.BitWizard.nl/ ** +31-15-2049110 **
**    Delftechpark 11 2628 XJ  Delft, The Netherlands.  KVK: 27239233    **
f equals m times a. When your f is steady, and your m is going down
your a** is going up.  -- Chris Hadfield about flying up the space shuttle.
**  'a' for accelleration.

On Wed, Nov 20, 2024 at 02:30:59PM -0500, FPA via Discuss wrote: > That works beautifully. Thanks to all. Note that this has happend once or twice in the past that someone tries do "difference" something and unexpectedly "nothing happens". Openscad has a trick: Prefix the thing that's not working with # and it will show up as a see-through pink object. Often you'll see what's wrong immediately. Roger. > > Fred > > On 2024-11-20 12:10, Mark Erbaugh via Discuss wrote: > > The cut out cylinder is positioned on top of the cube, so it is not > > cutting anything.  Change the last statement to: > > > > translate ( [w/2, w/2, h-wt-0.001]) cylinder ($fn=200,h=wt*2, d = hd); > > > > Note that it is lowering the translation by the wall thickness so the > > bottom of the cylinder is at the bottom of the top wall. > > > > Mark > > > > > > > > > On Nov 20, 2024, at 10:25 AM, fpa512--- via Discuss > > > <discuss@lists.openscad.org> wrote: > > > > > > Hi’yall > > > > > > As rookie, I have s small problem with a script when creating a cube > > > with some cut outs. > > > > > > I have the following code: > > > > > > // create switch housing > > > > > > w = 30; // width of cube > > > > > > h = 40; // height of cube > > > > > > hd = 16; // hole diameter for switch > > > > > > wt = 2; // wall-thickness > > > > > > difference () { > > > > > > cube([w, w, h], false); > > > > > > translate ( [wt, wt, 0] ) cube([w-wt*2, w-wt*2, h-wt], false); > > > > > > translate ( [w/2, w/2, h-0.001]) cylinder ($fn=200,h=wt*2, d = hd); > > > > > > }; > > > > > > I’m having a problem with the 2nd ‘translate’. > > > > > > It supposed to cut out the opening for the switch in the housing. > > > > > > What am I doing wrong here? > > > > > > Any help is much appreciate. > > > > > > TIA > > > > > > > > > Version: OpenSCAD *version 2024.08.18.ai20248 (git a16ca2a67)* > > > > > > on Linux Mint v22.3 > > > > > > _______________________________________________ > > > OpenSCAD mailing list > > > To unsubscribe send an email to discuss-leave@lists.openscad.org > > > > > > _______________________________________________ > > OpenSCAD mailing list > > To unsubscribe send an email todiscuss-leave@lists.openscad.org > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org -- ** R.E.Wolff@BitWizard.nl ** https://www.BitWizard.nl/ ** +31-15-2049110 ** ** Delftechpark 11 2628 XJ Delft, The Netherlands. KVK: 27239233 ** f equals m times a. When your f is steady, and your m is going down your a** is going up. -- Chris Hadfield about flying up the space shuttle. ** 'a' for accelleration.
RW
Rogier Wolff
Thu, Nov 21, 2024 10:59 AM

On Wed, Nov 20, 2024 at 11:47:28PM +0000, Caddiy via Discuss wrote:

Another useful feature is center=true. It anchors objects in their
centre, which simplifies things in most, but not all cases. I use it
about 80% of the time. Regrettably, it’s not the default.

Create a module that does it for you:

module ccube (size) cube (size, center=true);

Put it with the other "stuff I always use" in an include.
(I have stuff in there like dup2() : Duplicates an object by rotating
it around the origin, along with dup3(), dup4() and dupn(n) ).

Roger. 

--
** R.E.Wolff@BitWizard.nl ** https://www.BitWizard.nl/ ** +31-15-2049110 **
**    Delftechpark 11 2628 XJ  Delft, The Netherlands.  KVK: 27239233    **
f equals m times a. When your f is steady, and your m is going down
your a** is going up.  -- Chris Hadfield about flying up the space shuttle.
**  'a' for accelleration.

On Wed, Nov 20, 2024 at 11:47:28PM +0000, Caddiy via Discuss wrote: > Another useful feature is center=true. It anchors objects in their > centre, which simplifies things in most, but not all cases. I use it > about 80% of the time. Regrettably, it’s not the default. Create a module that does it for you: module ccube (size) cube (size, center=true); Put it with the other "stuff I always use" in an include. (I have stuff in there like dup2() : Duplicates an object by rotating it around the origin, along with dup3(), dup4() and dupn(n) ). Roger. -- ** R.E.Wolff@BitWizard.nl ** https://www.BitWizard.nl/ ** +31-15-2049110 ** ** Delftechpark 11 2628 XJ Delft, The Netherlands. KVK: 27239233 ** f equals m times a. When your f is steady, and your m is going down your a** is going up. -- Chris Hadfield about flying up the space shuttle. ** 'a' for accelleration.