4

For a project I need to automate the conversion of plenty .svg-files to .dxf-files for further processing.

Situation: One directory with plenty .svg-files which should be converted to .dxf (no matter if the .dxf files are in the same diretory or in a subfolder, dxf name should be svg name)

I can do that with Inkscape GUI which also works for importing the .dxf files in CAD programs, but as mentioned I need to automate that. (I've only written in Python so far).

My thought: I open the files in Inkscape via command line. Exporting in png-format would be possible via command with following code:

from subprocess import call
import os

svg_dir = "C:\\temp\\layers\\"
files = [svg_dir + i for i in os.listdir(svg_dir) if ".svg" in i]

dir = r"C:\Program Files\Inkscape"
for i in files:

    cmdline = "Inkscape -z -f "+ i +" -e "+ i + ".png"
    rc = call("start cmd /K " + cmdline, cwd=dir, shell=True) 

But I do not really unterstand Inkscape extensions. I only know that I need dxf_outlines.py/.inx in the extension directory. I always need the same export options so could I just rewrite the Python code for that and run it via command in Inkscape?

Or would there be any solution without any extra software like Inkscape in Python? As far as I've seen there isn't.

C.Joe
  • 51
  • 1
  • 3

2 Answers2

1

I came up with a slightly different solution but still made my way to the needed .dxf-files. I saved my figures in Python as .eps-files and could convert them with just one command line with pstoedit.

def eps_to_dxf():
    eps_list = [i for i in os.listdir(eps_directory) if ".eps" in i]
    work_directory = "C:\Program Files\pstoedit"

    for i in eps_list:
        input_file = i.split(".")[0]
        output_file = input_file + ".dxf"
        cmdline = "pstoedit -f dxf_s " + eps_directory + i + " " + eps_directory + output_file
        subprocess.check_call(cmdline, cwd=work_directory, shell=True)
C.Joe
  • 51
  • 1
  • 3
0

This is a Linux command to convert svg file to dxf with Inkscape

python /usr/share/inkscape/extensions/dxf12_outlines.py --output="output.dxf" "input.svg"