OpenSCAD .csv driven batch exporter by tdeagan 3d model
Warning. This content is not moderated and could be offensive.
ammo
3dmdb logo
Thingiverse
OpenSCAD .csv driven batch exporter by tdeagan

OpenSCAD .csv driven batch exporter by tdeagan

by Thingiverse
Last crawled date: 3 years ago
here is a Python script that will execute a batch series of OpenSCAD command lines driven from a .csv file. You can use it to generate a set of images, a set of .STLs or whatever formats are now or future supported.
It uses OpenSCAD's -D capability to populate variables on the command line. Since OpenSCAD determines the output format from the extension of the output filename, that is driven from the .csv as well.
The .CSV would would like this:
FILE,ARGS,able, baker, charlie
"test1.png","--render --projection=o",10,20,30
"test2.stl",,20,30,40
"test3.stl",,30,40,50
for an OpenSCAD file like this:
able = 10;
baker= 10;
charlie = 10;
cube([able,baker,charlie]);
on Debian, the command
python3 openscad_batch.py -x params.csv test.scad
would generate (and optionally execute if the -x was missing,) a series of command lines like this:

openscad --render --projection=o -D "baker=20" -D "able=10" -D "charlie=30" -o test1.png test.scad


openscad -D "baker=30" -D "able=20" -D "charlie=40" -o test2.stl test.scad

openscad -D "baker=40" -D "able=30" -D "charlie=50" -o test3.stl test.scad
Notes:
it's Python 3 (sorry, but I've moved on. 3 is the future.)
it needs a recent version of OpenSCAD to be able to do things like render (see OpenSCAD docs for a list of which command line switches each version of OpenSCAD supports.
call it with -h to get instructions (you can also read them in the source below
I've tested on Windows 8.1 and Debian 64 bit
Here's the help it generates:
usage: openscad_batch.py [-h] [-x] CSV OPENSCAD_FILE

Run OpenSCAD repeatedly with parameters driven from a .csv file.

---------- USAGE NOTES ----------------
* First _row_ of .csv contains paramter names (i.e. OpenSCAD constants)

NOTE: do not enclose parameter names in quotes.

* First _column_ of first _row_ must be named FILE.
* First _column_ of subsequent rows must contain output
file name for that row's values and be in double
quotes (e.g. "cube1.stl")

* Second _column_ of first _row_ must be named ARGS
* Second _column_ of subsequent rows must contain
OpenSCAD cmd line args for that file output or
be empty
(e.g. ,"--render", for a .png output or ,, for
a line with no args)

* String values in subsequent rows must be enclosed in double quotes.
* OpenSCAD executable must be in the PATH

positional arguments:
CSV location of .csv file containing params
OPENSCAD_FILE name of OpenSCAD file (without args)

optional arguments:
-h, --help show this help message and exit
-x Don't execute command line (just send output to console)

EXAMPLE COMMANDS:
c:python34python openscad_batch.py params.csv cubeout.scad
python openscad_batch.py -x params.csv cubeout.scad

(linux)
python3 openscad_batch.py params.csv cubeout.scad

EXAMPLE .CSV FILE:
FILE,ARGS,able,baker,charlie
"cube1.png","--render",10,20,30
"cube2.stl",,20,30,40
"cube3.stl",,30,40,50

works with .scad file:
able = 10;
baker= 10;
charlie = 10;

cube([able,baker,charlie]);

Tags