OpenSCAD multiple target
Description
OpenSCAD has the option to be used in a Makefile to handle complex projects, but i didn't found a simple way to handle simpler project where i want 3 or 4 stl files to be produced.
So i decided to write this little bash script to parse an openscad files and repeatedly call openscad for each target defined with a simple syntax.
This script is written for the bash shell, and it uses the sed command. It works on my MacOSX and linux and should work on a Windows-with-cygwin environment.
If you want to follow the development or maybe propose some changes use this repository:
git@bitbucket.org:hariseldon78/openscad_make_multiple_targets.git
As usual, run at your risk and never run untrusted scripts as root.
On my system this script works and produce good stl files :)
So i decided to write this little bash script to parse an openscad files and repeatedly call openscad for each target defined with a simple syntax.
This script is written for the bash shell, and it uses the sed command. It works on my MacOSX and linux and should work on a Windows-with-cygwin environment.
If you want to follow the development or maybe propose some changes use this repository:
git@bitbucket.org:hariseldon78/openscad_make_multiple_targets.git
As usual, run at your risk and never run untrusted scripts as root.
On my system this script works and produce good stl files :)
Instructions
In your scad file
- insert a comment like this:
- for each line that is specific to one or more models append a comment like this
in this example the first target will contain shape1 and shape2, the second target will contain only shape3 and the third target will contain only shape1.
In the script
These steps are just for the first time:
- edit the script and specify the path where OpenSCAD executable can be found. If you use MacOSX and it is in your Application folder you can skip this step.
- place the script in a place where you can execute it (like /usr/local/bin)
- make it executable (chmod +x script_path)
Run the script
From the terminal cd into the folder containing your scad file and run the script like this:
It will show you which targets it found and call openscad for each one, generating the correct stl files. Each time you call it it overwrites the stl files.
- insert a comment like this:
// TARGETS: ##first ##second ##third
- for each line that is specific to one or more models append a comment like this
shape1(); // ##first ##third
shape2(); // ##first
shape3(); // ##second
in this example the first target will contain shape1 and shape2, the second target will contain only shape3 and the third target will contain only shape1.
In the script
These steps are just for the first time:
- edit the script and specify the path where OpenSCAD executable can be found. If you use MacOSX and it is in your Application folder you can skip this step.
- place the script in a place where you can execute it (like /usr/local/bin)
- make it executable (chmod +x script_path)
Run the script
From the terminal cd into the folder containing your scad file and run the script like this:
make_targets_scad myModel.scad
It will show you which targets it found and call openscad for each one, generating the correct stl files. Each time you call it it overwrites the stl files.


You must be logged in to post a comment.