3D part design with Inkscape and OpenSCAD #93: reverse engineering an stl file part 4-Autoslice Version 3

Another example of how to cut an stl into multiple slices using OpenSCAD

2 min read
By Bob
3D part design with Inkscape and OpenSCAD #93: reverse engineering an stl file part 4-Autoslice Version 3
It's not the length of the code that matters, it's what you can do with it. :)

The last post was handy for making things like a simulated time lapse and you could grab an individual cut at a certain layer but it needed some improvements. The new version  aligns the slices to a grid so the whole object can be exported at one time and then edited in Inkscape. I didn't use animation this time and it would be pretty easy to implement but I didn't think it was necessary.

here is the code:

/*[STL Autoslice V3]*/
Path_to_STL_File="";
Show_cut_box=true;
Max_cut_height=10;//[0:.01:400]
width_x=50;//[1:.01:400]
width_y=50;//[1:.01:400]
layer_thickness=1;//[.2:.01:100]


module Box(){
#import(Path_to_STL_File);
linear_extrude(Max_cut_height)
square([width_x,width_y],center=true);
}

module slicerV3(){
n=ceil(sqrt((Max_cut_height)/layer_thickness)+1);
for(z=[-Max_cut_height:layer_thickness:0]){
i=(z+Max_cut_height)/layer_thickness;
x=width_x*floor(i%n);
y=width_y*floor(i/n);
translate([x,y,0]){
render()
projection(cut=true)
translate([0,0,z])
#import(Path_to_STL_File);
}}}


if(Show_cut_box){
color("green",.1)
intersection(){
%Box();
%import(Path_to_STL_File);
}}

slicerV3();

>The part of this code using the floor function was found on another post someone made and I can't find the site again, if I find it I will post an update with the link.

For the example in the pictures I used this stl file just to see how the layers would look:

Super Swamper extruder knob for Ender-3 pro by Arthur120
Just my remix of Gaslands Super Swamper Wheel+Tire 13mm by AdamDC for use as my extruder knob for my Ender-3 pro. I’m not sure what else it will fit.

With the layer thickness set to .20 mm it took about 1 minute and 12 seconds to render, I would recommend setting the default to a thicker setting like 2 mm so it doesn't take long to render when you are trying things out. I haven't had the patience to try slicing at .01 layer thickness yet, but it probably won't take all that long.

Now the slices can be imported into Inkscape and edited individually



Since you can have as many instances of Inkscape and OpenSCAD open as you want it's pretty easy to copy and paste from one screen to another.