Alternatively what you could do is export the STL, and import it into openscad.
It has a projection method to create the outline. I found this method more accurate than exporting to PNG and use Inkscape to vertorize it. And I also found this to be more accurate than using freestyle to export the contour to svg. Depending on your purpose Freestyle might be accurate enough, but I need the vectors for lasercutting, and it needs to be exact.
This would be the script for openscad.
projection(cut=false) {
import("C:/my/absolute/path/to/model.stl", convexity=3);
}
Make sure to face your model upwards along the z-azis, as this is the axis openscad uses for its projection. (Of course you could also use the rotate method in openscad).
Openscad can export to SVG or DXF (among others).
Openscad should be usable via the commandline as well like this:
import os
import subprocess
from subprocess import run
openscadPath = "C:\Program Files\OpenSCAD\openscad.exe"
def stlToDxf(stlFilePath):
openscadFileContents = "projection(cut=false) {\r\nimport("" + stlFilePath.replace('\', '\\') + "", convexity=10);\r\n}"
filepath = os.path.splitext(stlFilePath)[0] + '.scad'
f = open(filepath, "w")
f.write(openscadFileContents)
f.close()
outputFile = (os.path.splitext(stlFilePath)[0] + '.dxf')
_export(filepath, outputFile)
def _export(file, outputFile):
commands = [
openscadPath,
"-o",
outputFile,
file
]
rc = run(commands)
Little remark:
I never meant to move away from Blender to some other software and advertise in any way for it. I really wish Blender had this accurate SVG/DXF export capability. I found the way that modeling works in Blender via its API is way easier than openscad, because Blender keeps object references.

See below a result I've obtained using freestyle, a top border is missing. Not sure why, I tried playing around with several settings (contour, border, silhouette)...
