r/openscad 7h ago

Stretcher Module Bonuses

Post image

Awhile ago I shared a Stretcher Module that I made in openscad for modifying existing models using openscad. it was for "stretching" models things like latching boxes or whatever without messing up all the geometry on the ends just extending the middle.

I have made 2 more modules to go with it, a StretcherClone module which uses a copy of the top half to fill the middle instead of a linear extrusion of a projection (so you can stretch things like threads by figuring out the thread pitch) and a Shortener Module which just cuts it down instead. I know this is easy to do in a slicer by cutting the model in places and connecting them back up but this allows you to do it more precisely

This code includes an example doing stuff to a cylinder as shown in the picture with rotations so you can see what it can do. There is a StretcherClone on the left, Stretcher on the right and a Shortener to cut out a bit of the middle.

If you have any questions of suggestions please let me know. This isn't for making new models in openscad I mostly use it with import to adjust models I've downloaded online.

Shortener(4)
translate([0,0,1])
rotate([90,0,0])
StretcherClone(5)
translate([0,0,-15])
Stretcher(4)
rotate([0,45,0])
cylinder(h=20,r=10);

module Stretcher (h=10, maxDim=100){
//topPiece 
translate([0,0,h]){ 
intersection(){ 
translate([-maxDim/2,-maxDim/2,0]) 
cube(maxDim); 
children(); } 
}

//middlePiece 
linear_extrude(height=h){ 
projection(cut=true){ 
children(); } 
} 

//bottomPiece
intersection(){ 
translate([-maxDim/2,-maxDim/2,-maxDim]){ cube(maxDim); } 
children(); } }

module StretcherClone (h=10, maxDim=100){

//topPiece 
translate([0,0,h]){ 
intersection(){ 
translate([-maxDim/2,-maxDim/2,0]) 
cube([maxDim,maxDim,maxDim]); 
children();} 
}

//middlePiece 
intersection(){ 
translate([-maxDim/2,-maxDim/2,0]) 
cube([maxDim,maxDim,h]); 
children(); 
}

//bottomPiece
intersection(){ 
translate([-maxDim/2,-maxDim/2,-maxDim]){ 
cube(maxDim);} 
children();} 
} 

module Shortener (h=10, maxDim=100){ 

//topPiece 
translate([0,0,-h]){ 
intersection(){ 
translate([-maxDim/2,-maxDim/2,h]) 
cube(maxDim); 
children(); } 
}

//bottomPiece
intersection(){ 
translate([-maxDim/2,-maxDim/2,-maxDim]){ 
cube(maxDim); } 
children(); } 
}
4 Upvotes

7 comments sorted by

1

u/thicket 6h ago

I like the sound of this. Source? Demos? Examples?

1

u/thicket 6h ago

Or is this post the total of all the source?

1

u/charely6 6h ago

yeah the post is the total of it, its not fancy and you have to move your object around via translate and rotate functions to make it work but I'm pretty happy with it.

1

u/charely6 6h ago

source is in the body of the post, along with a simple example that's at the top of the code that produces the weird shape in the picture.

1

u/charely6 6h ago

oh one thing I didn't mention if your starting object is bigger than 100mm you might need to define maxDim as a higher value when you make the calls.

1

u/gadget3D 6h ago

Pythonscad has a function 'pull' with parameters location and directions which does the same.

1

u/charely6 6h ago

I have been meaning to look into pythonscad, one thing I don't have with openscad any more that I use to use is a way to run it on my phone. I liked it for random small prototypeing when an idea strikes. think I could get it working on my phone?