In post #131 I made what I called a "3d fill" module that filled in the empty spaces of a 3d object. In this post I'm going to add to that with a selector that you can move, cut out the section you want to use and then fill it back in to clone the item.
Note I am using the latest development release, scroll down to development snapshots to download it:
I made the "selector" code so you can resize and relocate the selector cube to surround the area you want to copy:
Then select the "perform difference" box:
Click render and save the stl file, import it into the 3d fill module and you have an exact copy of what was selected :
Here is the code example for the selector:
//3D fill Version 2-Selector
/*[File Import]*/
path_to_stl_file=("");
/*[Selector parameters]*/
Perform_difference=false;
Selector_sizeX=20;//[1:.1:400]
Selector_sizeY=20;//[1:.1:400]
Selector_sizeZ=20;//[1:.1:400]
Move_SelectorX=0;//[-360:.1:360])
Move_SelectorY=0;//[-360:.1:360])
Move_SelectorZ=0;//[-360:.1:360])
module selector(){
translate([Move_SelectorX,Move_SelectorY,Move_SelectorZ])
#color("red",.5)
linear_extrude(Selector_sizeZ)
square([Selector_sizeX,Selector_sizeY],center=true);
import(path_to_stl_file,center=true,convexity=6);
}
module perform_difference(){
difference(){
translate([Move_SelectorX,Move_SelectorY,Move_SelectorZ])
color("red",.5)
linear_extrude(Selector_sizeZ)
square([Selector_sizeX,Selector_sizeY],center=true);
import(path_to_stl_file,center=true,convexity=6);
}}
if(Perform_difference)
perform_difference();
else
selector();And the updated code for the 3D fill module:
//
//3D fill Version 2-Filler
path_to_stl_file=("");
Scale=1;//[.5:.001:1.5]
module ThreeDfill(){
color("dodgerblue")
hull(){
intersection(){
sphere(600);
import(path_to_stl_file,convexity=6);
}}}
render()
difference(){
scale([Scale,Scale,Scale])
ThreeDfill();
color("red")
import(path_to_stl_file,convexity=6);
}
Here are some screen shots of some of the other items I cloned for this post:
How good is the quality? Really good:
I did have an issue with one stl file not working and flagging a "not manifold" warning that doesn't allow this to work, this is a problem with my STL file not OpenSCAD. If there are any extra tiny slivers of an object hiding somewhere in the stl file it is next to impossible to find them to fix the problem even if it is repaired so the best option is to make files that don't have this problem to begin with.
As you can see looking at this board I made with KiCad it has alot more going on than is obvious at first, you can't see the traces and extra stuff in the stl file but they are clearly there.
But for the other models I tested this works great, and this is yet another example of the cool things you can do with just a few lines of code in OpenSCAD.
OpenSCAD tip for new users:
This might seem obvious but to someone unfamiliar with the process it can be confusing and a source of frustration, if you get a compile error it is usually because you are missing a comma, bracket, semicolon, etc. here is an example where I removed the semicolon to show the error:
I always have the console window set to show up under the view window so any errors like this will show up and I can look at the code to see what line I had the problem with.
Same thing with import errors:
It shows an unsupported file format error, the only problem is I didn't enter a path to the stl file and once I enter the path everything works fine. So long story short if you are having error codes pop up don't get discouraged it's probably a simple fix.