Created
December 7, 2021 13:59
-
-
Save foosel/02c8e77ae87a32986f051b0de9ef62fb to your computer and use it in GitHub Desktop.
STL to SVG conversion script using OpenSCAD. Takes an STL and projects it to the defined plane (default: XY), then saves the result as SVG.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FileToLoad = ""; | |
Plane=0; // 0: XY, 1: XZ, 2: YZ | |
echo("File:", FileToLoad); | |
projection() { | |
if (Plane == 0) { | |
echo("Plane: XY"); | |
import(FileToLoad); | |
} else if (Plane == 1) { | |
echo("Plane: XZ"); | |
rotate([90, 0, 0]) import(FileToLoad); | |
} else if (Plane == 2) { | |
echo("Plane: YZ"); | |
rotate([0, 90, 0]) import(FileToLoad); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
### Usage ### | |
# stl_to_svg.sh [-p {xy|xz|yz}] input.stl [output.svg] | |
# | |
# -p = Projection plane, xy, xz or yz | |
# input.stl = Input file | |
# output.svg = Output file, if not provided will default to input.stl.svg | |
# | |
#set -xe | |
OPENSCAD="/path/to/openscad" | |
SCAD="/path/to/stl_to_svg.scad" | |
plane=0 | |
while getopts "p:" opt; do | |
case $opt in | |
p) | |
case $OPTARG in | |
xy) | |
plane=0 | |
;; | |
xz) | |
plane=1 | |
;; | |
yz) | |
plane=2 | |
;; | |
*) | |
echo "Invalid plane definition, accepted values are xy, xz and yz" | |
exit -1 | |
;; | |
esac | |
;; | |
esac | |
done | |
shift $((OPTIND-1)) | |
[ "${1:-}" = "--" ] && shift | |
STL="$1" | |
SVG="$2" | |
[ -n "$SVG" ] || SVG="$STL.svg" | |
"$OPENSCAD" -o "$SVG" -D FileToLoad="\"$STL\"" -D Plane=$plane "$SCAD" |
Works really well, thank you!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice and useful, thanks a lot. Since Prusaslicer now allows to modify models with SVGs this comes quite handy!