discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Rectangular cut-out in wall

HW
Harvey white
Sun, Jun 1, 2025 4:12 PM

I'll throw in another one:

module holes()

 union()

 {

     // round hole
$fn = 40;
color("red") cylinder(d = 3, h = 30);

 }

 union()

 {

     // hex hole for nut
$fn = 6;
color("red") translate([0,0,n]) cylinder(d = 8, h = 3);

 }

}

position the holes wherever you want. There's one trick here:  the
$fn=40 is valid for the first union and produces a round hole.  The
large h value allows you to see where the hole really is (commenting out
the difference which is elsewhere).  you can use those long cylinders to
show where the holes are to align stacked pieces.

The second union has a $fn = 6 that is valid only for that union.  This
produces a hex hole for the nut (adjust d).  the translate value n moves
the cutout for the nut up and down the bore for the screw (3.0 is too
narrow for M3, but it's an example).  So place holes() where you need
it, and move the nut cutout down to the point where is scoops out a hole
for the nut.

Note the scope of variables in the unions().  It allows different shaped
holes.  You could use this method, with modifications, to countersink a
cap head screw.

Harvey

On 6/1/2025 11:50 AM, Peter Schmelzer via Discuss wrote:

Hi Harvey,
great idea. Thanks. I'll follow your suggestion in the future.

BR Peter

Am 01.06.2025 um 17:18 schrieb Harvey white via Discuss discuss@lists.openscad.org:

There are some tricks to make life easier:

I use a structure:

difference()

{

  union()

  {

      // define things here as base object

  }

  union()

  {

      // define things here as objects to be subtracted from base object

  }

}

The way difference works is that the first object (union, here, and anything in that union) is the base, everything else gets subtracted from it.  the second union contains  objects to be subtracted.

Generally, you'll have a difficult time positioning those objects, orientation, position, etc.  The trick is to comment out the difference().  That simply gives you the base object and the objects to be subtracted as objects.  I generally color them all red for visibility.  You can easily see where everything is. Uncommenting the difference() shows you the effect.

Harvey

On 6/1/2025 3:15 AM, peter--- via Discuss wrote:

Hi,

I have been trying for hours to create a rectangular cut-out for a USB connector in the enclosure wall.

I watched the tutorials, but found them very complex. I tried to understand how the ‘difference’ and ‘minkowski’ functions work. Unfortunately, I have to admit that I didn't understand how they work.

I looked at various examples on the Internet and tried to implement them. Unfortunately without success. The code, I’m using is from a Github repository.

It would be very nice if someone could tell me what I need to change in the source code to get the rectangle cut-out. It is the red rectangle. The source code is attached.

Thank you very much

Peter


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


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


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

I'll throw in another one: module holes() union() { // round hole $fn = 40; color("red") cylinder(d = 3, h = 30); } union() { // hex hole for nut $fn = 6; color("red") translate([0,0,n]) cylinder(d = 8, h = 3); } } position the holes wherever you want. There's one trick here:  the $fn=40 is valid for the first union and produces a round hole.  The large h value allows you to see where the hole really is (commenting out the difference which is elsewhere).  you can use those long cylinders to show where the holes are to align stacked pieces. The second union has a $fn = 6 that is valid only for that union.  This produces a hex hole for the nut (adjust d).  the translate value n moves the cutout for the nut up and down the bore for the screw (3.0 is too narrow for M3, but it's an example).  So place holes() where you need it, and move the nut cutout down to the point where is scoops out a hole for the nut. Note the scope of variables in the unions().  It allows different shaped holes.  You could use this method, with modifications, to countersink a cap head screw. Harvey On 6/1/2025 11:50 AM, Peter Schmelzer via Discuss wrote: > Hi Harvey, > great idea. Thanks. I'll follow your suggestion in the future. > > BR Peter > >> Am 01.06.2025 um 17:18 schrieb Harvey white via Discuss <discuss@lists.openscad.org>: >> >> There are some tricks to make life easier: >> >> I use a structure: >> >> difference() >> >> { >> >> union() >> >> { >> >> // define things here as base object >> >> } >> >> union() >> >> { >> >> // define things here as objects to be subtracted from base object >> >> } >> >> } >> >> >> The way difference works is that the first object (union, here, and anything in that union) is the base, everything else gets subtracted from it. the second union contains objects to be subtracted. >> >> Generally, you'll have a difficult time positioning those objects, orientation, position, etc. The trick is to comment out the difference(). That simply gives you the base object and the objects to be subtracted as objects. I generally color them all red for visibility. You can easily see where everything is. Uncommenting the difference() shows you the effect. >> >> Harvey >> >> >> On 6/1/2025 3:15 AM, peter--- via Discuss wrote: >>> Hi, >>> >>> I have been trying for hours to create a rectangular cut-out for a USB connector in the enclosure wall. >>> >>> I watched the tutorials, but found them very complex. I tried to understand how the ‘difference’ and ‘minkowski’ functions work. Unfortunately, I have to admit that I didn't understand how they work. >>> >>> I looked at various examples on the Internet and tried to implement them. Unfortunately without success. The code, I’m using is from a Github repository. >>> >>> It would be very nice if someone could tell me what I need to change in the source code to get the rectangle cut-out. It is the red rectangle. The source code is attached. >>> >>> >>> Thank you very much >>> >>> Peter >>> >>> >>> >>> >>> _______________________________________________ >>> OpenSCAD mailing list >>> To unsubscribe send an email to discuss-leave@lists.openscad.org >> _______________________________________________ >> OpenSCAD mailing list >> To unsubscribe send an email to discuss-leave@lists.openscad.org > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org
GH
gene heskett
Sun, Jun 1, 2025 5:01 PM

On 6/1/25 12:12, Harvey white via Discuss wrote:

I'll throw in another one:

module holes()

    union()

    {

        // round hole
    $fn = 40;
    color("red") cylinder(d = 3, h = 30);

    }

    union()

    {

        // hex hole for nut
    $fn = 6;
    color("red") translate([0,0,n]) cylinder(d = 8, h = 3);

    }
}

position the holes wherever you want. There's one trick here:  the
$fn=40 is valid for the first union and produces a round hole. The
large h value allows you to see where the hole really is (commenting
out the difference which is elsewhere).  you can use those long
cylinders to show where the holes are to align stacked pieces.

The second union has a $fn = 6 that is valid only for that union. This
produces a hex hole for the nut (adjust d).  the translate value n
moves the cutout for the nut up and down the bore for the screw (3.0
is too narrow for M3, but it's an example).  So place holes() where
you need it, and move the nut cutout down to the point where is scoops
out a hole for the nut.

Note the scope of variables in the unions().  It allows different
shaped holes.  You could use this method, with modifications, to
countersink a cap head screw.

Harvey

I'd add further, that multiple bolt patterns be made as a separate
module which are then identical anyplace else it the file where they
might be needed so bolt holes in parts can be always fitted w/o having
to reinvent that particular wheel every time you need it. One could even
have them as a separate file, included in the top few lines of the
current file.

On 6/1/2025 11:50 AM, Peter Schmelzer via Discuss wrote:

Hi Harvey,
great idea. Thanks. I'll follow your suggestion in the future.

BR Peter

Am 01.06.2025 um 17:18 schrieb Harvey white via Discuss
discuss@lists.openscad.org:

There are some tricks to make life easier:

I use a structure:

difference()

{

     union()

     {

         // define things here as base object

     }

     union()

     {

         // define things here as objects to be subtracted from base
object

     }

}

The way difference works is that the first object (union, here, and
anything in that union) is the base, everything else gets subtracted
from it.  the second union contains  objects to be subtracted.

Generally, you'll have a difficult time positioning those objects,
orientation, position, etc.  The trick is to comment out the
difference().  That simply gives you the base object and the objects
to be subtracted as objects.  I generally color them all red for
visibility.  You can easily see where everything is. Uncommenting
the difference() shows you the effect.

Harvey

On 6/1/2025 3:15 AM, peter--- via Discuss wrote:

Hi,

I have been trying for hours to create a rectangular cut-out for a
USB connector in the enclosure wall.

I watched the tutorials, but found them very complex. I tried to
understand how the ‘difference’ and ‘minkowski’ functions work.
Unfortunately, I have to admit that I didn't understand how they work.

I looked at various examples on the Internet and tried to implement
them. Unfortunately without success. The code, I’m using is from a
Github repository.

It would be very nice if someone could tell me what I need to
change in the source code to get the rectangle cut-out. It is the
red rectangle. The source code is attached.

Thank you very much

Peter


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


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


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


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

Cheers, Gene Heskett, CET.

"There are four boxes to be used in defense of liberty:
soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author, 1940)
If we desire respect for the law, we must first make the law respectable.

  • Louis D. Brandeis
On 6/1/25 12:12, Harvey white via Discuss wrote: > I'll throw in another one: > > module holes() > >     union() > >     { > >         // round hole >     $fn = 40; >     color("red") cylinder(d = 3, h = 30); > >     } > >     union() > >     { > >         // hex hole for nut >     $fn = 6; >     color("red") translate([0,0,n]) cylinder(d = 8, h = 3); > >     } > } > > position the holes wherever you want. There's one trick here:  the > $fn=40 is valid for the first union and produces a round hole. The > large h value allows you to see where the hole really is (commenting > out the difference which is elsewhere).  you can use those long > cylinders to show where the holes are to align stacked pieces. > > The second union has a $fn = 6 that is valid only for that union. This > produces a hex hole for the nut (adjust d).  the translate value n > moves the cutout for the nut up and down the bore for the screw (3.0 > is too narrow for M3, but it's an example).  So place holes() where > you need it, and move the nut cutout down to the point where is scoops > out a hole for the nut. > > Note the scope of variables in the unions().  It allows different > shaped holes.  You could use this method, with modifications, to > countersink a cap head screw. > > Harvey I'd add further, that multiple bolt patterns be made as a separate module which are then identical anyplace else it the file where they might be needed so bolt holes in parts can be always fitted w/o having to reinvent that particular wheel every time you need it. One could even have them as a separate file, included in the top few lines of the current file. > On 6/1/2025 11:50 AM, Peter Schmelzer via Discuss wrote: >> Hi Harvey, >> great idea. Thanks. I'll follow your suggestion in the future. >> >> BR Peter >> >>> Am 01.06.2025 um 17:18 schrieb Harvey white via Discuss >>> <discuss@lists.openscad.org>: >>> >>> There are some tricks to make life easier: >>> >>> I use a structure: >>> >>> difference() >>> >>> { >>> >>>      union() >>> >>>      { >>> >>>          // define things here as base object >>> >>>      } >>> >>>      union() >>> >>>      { >>> >>>          // define things here as objects to be subtracted from base >>> object >>> >>>      } >>> >>> } >>> >>> >>> The way difference works is that the first object (union, here, and >>> anything in that union) is the base, everything else gets subtracted >>> from it.  the second union contains  objects to be subtracted. >>> >>> Generally, you'll have a difficult time positioning those objects, >>> orientation, position, etc.  The trick is to comment out the >>> difference().  That simply gives you the base object and the objects >>> to be subtracted as objects.  I generally color them all red for >>> visibility.  You can easily see where everything is. Uncommenting >>> the difference() shows you the effect. >>> >>> Harvey >>> >>> >>> On 6/1/2025 3:15 AM, peter--- via Discuss wrote: >>>> Hi, >>>> >>>> I have been trying for hours to create a rectangular cut-out for a >>>> USB connector in the enclosure wall. >>>> >>>> I watched the tutorials, but found them very complex. I tried to >>>> understand how the ‘difference’ and ‘minkowski’ functions work. >>>> Unfortunately, I have to admit that I didn't understand how they work. >>>> >>>> I looked at various examples on the Internet and tried to implement >>>> them. Unfortunately without success. The code, I’m using is from a >>>> Github repository. >>>> >>>> It would be very nice if someone could tell me what I need to >>>> change in the source code to get the rectangle cut-out. It is the >>>> red rectangle. The source code is attached. >>>> >>>> >>>> Thank you very much >>>> >>>> Peter >>>> >>>> >>>> >>>> >>>> _______________________________________________ >>>> OpenSCAD mailing list >>>> To unsubscribe send an email to discuss-leave@lists.openscad.org >>> _______________________________________________ >>> OpenSCAD mailing list >>> To unsubscribe send an email to discuss-leave@lists.openscad.org >> _______________________________________________ >> OpenSCAD mailing list >> To unsubscribe send an email to discuss-leave@lists.openscad.org > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org Cheers, Gene Heskett, CET. -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author, 1940) If we desire respect for the law, we must first make the law respectable. - Louis D. Brandeis
JB
Jordan Brown
Mon, Jun 2, 2025 4:01 PM

On 6/1/2025 8:18 AM, Harvey white via Discuss wrote:

Generally, you'll have a difficult time positioning those objects,
orientation, position, etc.  The trick is to comment out the
difference().  That simply gives you the base object and the objects
to be subtracted as objects.  I generally color them all red for
visibility.  You can easily see where everything is. Uncommenting the
difference() shows you the effect.

Marking the pieces that you're interested in using the # modifier can
help a lot.  It makes the part marked be visible as transparent red.

difference() {
    cube(10);
    #sphere(10);
}
On 6/1/2025 8:18 AM, Harvey white via Discuss wrote: > Generally, you'll have a difficult time positioning those objects, > orientation, position, etc.  The trick is to comment out the > difference().  That simply gives you the base object and the objects > to be subtracted as objects.  I generally color them all red for > visibility.  You can easily see where everything is. Uncommenting the > difference() shows you the effect. Marking the pieces that you're interested in using the # modifier can help a lot.  It makes the part marked be visible as transparent red. difference() { cube(10); #sphere(10); }
PS
Peter Schmelzer
Mon, Jun 2, 2025 8:26 PM

Thank you very much for your great tips and advice. You are a really great community!

Peter

Am 02.06.2025 um 18:02 schrieb Jordan Brown via Discuss discuss@lists.openscad.org:


On 6/1/2025 8:18 AM, Harvey white via Discuss wrote:

Generally, you'll have a difficult time positioning those objects, orientation, position, etc.  The trick is to comment out the difference().  That simply gives you the base object and the objects to be subtracted as objects.  I generally color them all red for visibility.  You can easily see where everything is. Uncommenting the difference() shows you the effect.

Marking the pieces that you're interested in using the # modifier can help a lot.  It makes the part marked be visible as transparent red.
difference() {
cube(10);
#sphere(10);
}
<2IWI0bYy70WgFeVx.png>


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

Thank you very much for your great tips and advice. You are a really great community! Peter > Am 02.06.2025 um 18:02 schrieb Jordan Brown via Discuss <discuss@lists.openscad.org>: > >  > On 6/1/2025 8:18 AM, Harvey white via Discuss wrote: >> Generally, you'll have a difficult time positioning those objects, orientation, position, etc. The trick is to comment out the difference(). That simply gives you the base object and the objects to be subtracted as objects. I generally color them all red for visibility. You can easily see where everything is. Uncommenting the difference() shows you the effect. > > Marking the pieces that you're interested in using the # modifier can help a lot. It makes the part marked be visible as transparent red. > difference() { > cube(10); > #sphere(10); > } > <2IWI0bYy70WgFeVx.png> > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org
BC
Bob Carlson
Tue, Jun 3, 2025 12:15 AM

I will occasionally use a construction like this when I need to make holes that go through multiple parts. Its depends on the overall structure whether this approach is more readable than a standard one.

module applyHoles() {
difference() {
union() {children();}

	holes();
}

}

applyHoles() part();

The holes can then be cut in any parts as long as they are positioned correctly relative to each other.

-Bob

On Jun 2, 2025, at 13:26, Peter Schmelzer via Discuss discuss@lists.openscad.org wrote:

Thank you very much for your great tips and advice. You are a really great community!

Peter

Am 02.06.2025 um 18:02 schrieb Jordan Brown via Discuss discuss@lists.openscad.org:


On 6/1/2025 8:18 AM, Harvey white via Discuss wrote:

Generally, you'll have a difficult time positioning those objects, orientation, position, etc.  The trick is to comment out the difference().  That simply gives you the base object and the objects to be subtracted as objects.  I generally color them all red for visibility.  You can easily see where everything is. Uncommenting the difference() shows you the effect.

Marking the pieces that you're interested in using the # modifier can help a lot.  It makes the part marked be visible as transparent red.
difference() {
cube(10);
#sphere(10);
}

<2IWI0bYy70WgFeVx.png>


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


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

I will occasionally use a construction like this when I need to make holes that go through multiple parts. Its depends on the overall structure whether this approach is more readable than a standard one. module applyHoles() { difference() { union() {children();} holes(); } } applyHoles() part(); The holes can then be cut in any parts as long as they are positioned correctly relative to each other. -Bob > On Jun 2, 2025, at 13:26, Peter Schmelzer via Discuss <discuss@lists.openscad.org> wrote: > > Thank you very much for your great tips and advice. You are a really great community! > > Peter > >> Am 02.06.2025 um 18:02 schrieb Jordan Brown via Discuss <discuss@lists.openscad.org>: >> >>  >> On 6/1/2025 8:18 AM, Harvey white via Discuss wrote: >>> Generally, you'll have a difficult time positioning those objects, orientation, position, etc. The trick is to comment out the difference(). That simply gives you the base object and the objects to be subtracted as objects. I generally color them all red for visibility. You can easily see where everything is. Uncommenting the difference() shows you the effect. >> >> Marking the pieces that you're interested in using the # modifier can help a lot. It makes the part marked be visible as transparent red. >> difference() { >> cube(10); >> #sphere(10); >> } >> >> <2IWI0bYy70WgFeVx.png> >> >> _______________________________________________ >> OpenSCAD mailing list >> To unsubscribe send an email to discuss-leave@lists.openscad.org > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org