3D part design with Inkscape and OpenSCAD#92: Reverse Engineering an stl file part 3: Automating with animation

4 min read
By Bob
3D part design with Inkscape and OpenSCAD#92: Reverse Engineering an stl file part 3: Automating with  animation
* Lawnmower replacement knob modeled by (Robert) owner of Infinityplays.com

By adding the $t command in a few places I was able to automate the slicer module I made in post #88 so it will automatically slice the layers and it can either be paused to save an svg or an stl at that layer or output the layers as individual pictures that can make an animated gif like the one that is running above.

Here is the modified code:

Path_to_STL_File="/home/none3/Desktop/.stl";

/*[Cut to SVG]*/
//__________________________________________
Slice_SVG=true;
Cut_svg_layer = 1; //[-200:.01:200]
Cut_width=.03;//[0:.01:200]
Rotate_svg_x=0;//[-360:.01:360]
Rotate_svg_y=0;//[-360:.01:360]
Rotate_svg_z=0;//[-360:.01:360]

/*[Cut to STL]*/
//__________________________________________
Slice_STL=false;
Cut_start = 0; //[-200:.1:200]
Cut_end= 60; //[-200:.1:200]
Rotate_x=0;//[-360:.01:360]
Rotate_y=0;//[-360:.01:360]
Rotate_z=0;//[-360:.01:360]

//set the desired fps and steps in the animation window

module Slice_to_SVG(){
if(Slice_SVG){
 color("blue",alpha=.1)
%cube(400,center=true);
 translate([0, 0, $t*Cut_svg_layer])
 rotate([Rotate_svg_x,Rotate_svg_y,Rotate_svg_z])
 color("blue",alpha=.1)
 %square(400,center=true);
 color("red",alpha=.3)
 %import(Path_to_STL_File);
 
 render(){
 intersection(){
 color("red")
 rotate([Rotate_svg_x,Rotate_svg_y,Rotate_svg_z])
 import(Path_to_STL_File);
 translate([0, 0,$t*Cut_svg_layer])
 rotate([Rotate_svg_x,Rotate_svg_y,Rotate_svg_z])
 linear_extrude(Cut_width)
 square(400,center=true);
}
}}}

module Slice_to_STL(){
if(Slice_STL){
 color("blue",alpha=.1)
%cube(400,center=true);
 translate([0, 0, Cut_start])
 rotate([Rotate_x,Rotate_y,Rotate_z])
 color("blue",alpha=.1)
 %square(400,center=true);
 translate([0, 0,$t* Cut_end])
 rotate([Rotate_x,Rotate_y,Rotate_z])
 color("red",alpha=.1)
 %square(400,center=true);

 render()
 intersection(){
 import(Path_to_STL_File);
 rotate([Rotate_x,Rotate_y,Rotate_z])
 translate([-200,-200,$t* Cut_start])
 linear_extrude(Cut_end,convexity=8)
 square(400,Cut_start);
}}}

if (Slice_SVG){
projection(){
//translate([0, 0,Cut_svg_layer])
Slice_to_SVG();
}}


Slice_to_STL();
 
 

If you make a folder to put the OpenSCAD file into, you can dump the images into that folder and make an animated GIF:

Propeller modeled with Inkscape and OpenSCAD by me

You can use the measurement tool to select the height you want to slice to and set the cut svg layer to that, I set the FPS to 12 and steps to 80 (55mm/80=.6875mm per slice):

Once there is a value set in the animation window you can pause the animation and manually set the section you want to cut out with the slider, eventually I will add a check box to separate the two so the model can be sliced manually or automatically.

Ramps enclosure designed by me with Inkscape and OpenSCAD

If you have a part that extends in the negative direction just set the cut svg layer setting to the last slice you want in the negative direction, then it will slice down instead of up.

The number of steps set in the animation window will determine the number of screen shots saved.

Then it's pretty easy to open that folder with the terminal and convert the files to a GIF file:

from the OpenSCAD Wikibooks page
OpenSCAD User Manual/Other Language Features - Wikibooks, open books for an open world
scroll up to the animation section

In this post I went through a method to add an animation made with OpenSCAD to a video:

Using OpenScad and Gimp to make 3d objects for video
If you have ever wanted to add your 3D models to a video here is a simple method to do that.

I will have to do some experimenting to see what kind of cool videos can be made with this new module, or if the output can be converted to different file types like .svg.

As usual there is still a bunch of things that need to be worked on to make this more usable.