Saturday, 7 January 2012

Automated stl creation and slicing.

Kaizen is the Japanese technique of continuous improvement. I.E. Spotting an area in your current process where a small change would make an improvement.

Recently I posted an OpenSCAD / STL file to Thingiverse but did not realise that when being sliced it came up with the dreaded 'your mesh is not manifold' error. To fix this I went back though the OpenSCAD file commenting out an operation and running a Render/Export from OpenSCAD, then running a slice with Slic3r until I found the operation that caused the error.  Each time this involved several clicks of the mouse, selecting in dialog boxes etc.  Eventually I thought there must be a different way.

Looking at the OpenSCAD and Slic3r documentation I realised there was.  Both have a command line option, so I could write a quick script to automate the operation.

The first stumbling block, this is computers there are always stumbling blocks, was that I work on a Mac and to execute either program from a script / command line is a bit cumbersome, so I created a symbolic link for each that made them easily accessible from the command line.
   sudo ln -s /Applications/ /usr/local/bin/openscad   
   sudo ln -s /Applications/ /usr/local/bin/slic3r   
Now from a Terminal session I can type openscad or slic3r and the application opens up.

The next thing was to create a shell script that uses those.

In my local work directory I created a file, oss, that contains the following:

   openscad -s $1.stl  $1.scad   
   slic3r --load ~/projects/mechanical/Slic3rConfigs/yellow_abs.INI --gcode-arcs $1.stl   

The #!/bin/bash line indicates which shell processor is required.

The $1 represents the first parameter after the script name

The openscad line processes the scad file and outputs an stl file with the same filename, but stl prefix.

The slic3r line loads my standard config file for the ABS filament currently in my Prusa. This will need to be edited when I load a different filament into the machine.

The --gcode-arcs option enables an experimental option in Slic3r that uses G2/G3 codes to draw arcs.  Not all firmwares support this, I use Marlin which does.

Having saved the file I setup another symbolic link to allow oss to be executed from anywhere. So:

   ln -s full_path_to_oss /usr/local/bin/oss   

On my machine the full path is /Users/geoffd/projects/mechanical/oss, you need to use the one for your configuration.

And that's it, now I can switch to the directory containing my scad files, type oss filename, press return and within a few seconds my file has been rendered, exported as stl and sliced for my current setup.  Kaizen in action.

For more details of the available command line options see OpenSCAD and Slic3r under command line usage.

As I said I use a Mac, so these instructions will also work on a Linux machine, but with slightly different source paths for the symbolic links.  On Windows you will need to use a batch file and full paths names.  I haven't used Windows for quite some time and don't have access to a machine that I can try them on.

Happy slicing.


No comments:

Post a Comment