1

I need to convert multiple SVG files to DXF for use with a laser cutter. I know how to do it with Inkscape using the GUI using File > Save As, but it is tedious if I have a lot of files to convert.

So I have found how to batch export using Inkscape command line :

$ inkscape --export-type="dxf" *.svg

The GUI lets you choose between DXF R12 or DXF R14 format, and the command above seems to use the DXF R12 format.

How to use the DXF R14 format with the command line?

2 Answers 2

2

I had the same question and downloaded the Inkscape source from https://gitlab.com/inkscape/inkscape in order to understand the internal mechanisms.

A full-text search for R12 and R14 revealed that these formats are exported using Inkscape extensions, dxf12_outlines and dxf_outlines, respectively (output shortened):

[~/source/inkscape]$ grep R12 po/de.po -C 1                                                                                                                                                                                                                                      
#: ../share/extensions/dxf12_outlines.inx:9
msgid "Desktop Cutting Plotter (AutoCAD DXF R12) (*.dxf)"
msgstr "Desktop-Schneideplotter (AutoCAD DXF R12) (*.dxf)"

[~/source/inkscape]$ grep R14 po/de.po -C 1
#: ../share/extensions/dxf_outlines.inx:49
msgid "Desktop Cutting Plotter (AutoCAD DXF R14) (*.dxf)"
msgstr "Desktop-Schneideplotter (AutoCAD DXF R14) (*.dxf)"

I then learned that the Inkscape extensions live in their separate repository at https://gitlab.com/inkscape/extensions. Looking at the source of dxf_outlines.py, the docstrings confirm that this script effectively outputs the R14 format: https://gitlab.com/inkscape/extensions/-/blob/master/dxf_outlines.py#L22

On my Ubuntu 20 system with Inkscape installed via snap, the script is executed as follows:

/usr/bin/python3 /snap/inkscape/current/share/inkscape/extensions/dxf_outlines.py --output=file.dxf file.svg

As a prerequisite, I had to install the lxml and numpy extensions for Python 3:

sudo apt install python3-lxml python3-numpy

Hope this helps!

1
  • Thanks for the investigation. On my Mac I found the script in /Applications/Inkscape.app/Contents/Resources/share/inkscape/extensions/dxf_outlines.py Commented Oct 20, 2021 at 7:33
0

Inkscape has the concept of "export extensions" and there are two separate export extensions for DXF r12 and r14.

DXF r12

  • Extension name: org.inkscape.output.dxf_twelve
  • Extension file name: dxf12_outlines.inx

DXF r14

  • Extension name: org.ekips.output.dxf_outlines
  • Extension file: dxf_outlines.inx

Specifify extension in Inkscape CLI:

E.g. r14:

$ inkscape \
    --export-type="dxf" \
    --export-extension="org.ekips.output.dxf_outlines" \
    *.svg

Get list of possible extensions

If you don't know or cant remember which extensions are available for a specific file format, you can specify an invalid extension, and Inkscape will provide a useful help message listing the possible extensions.

$ inkscape \
    --export-type="dxf" \
    --export-extension="org.ekips.output.dxf_outlines" \
    *.svg
InkFileExportCmd::do_export: The supplied extension ID (INVALID) does not match any of the extensions available for this file type.
Supported IDs for this file type: [org.inkscape.output.dxf_twelve, org.ekips.output.dxf_outlines]

Extension options (ROBO-Master, LWPOLYLINE, etc.)

Unfortunately, it seems that there is no way to pass these options to the extension via Inkscape CLI. Source: Inkscape - Set Extension Parameters from Command Line

My current solution is running the Python script that does the work in the background. See lutuh's answer.

Running dxf_outlines.py with options

Calling dxf_outlines.py --help will give some help:

$ dxf_outlines.py --help
usage: dxf_outlines.py [-h] [--output OUTPUT] [--tab TAB] [-R ROBO] [-P POLY] [--units UNITS] [--encoding CHAR_ENCODE] [--layer_option LAYER_OPTION]
                       [--layer_name LAYER_NAME] [--id IDS] [--selected-nodes SELECTED_NODES]
                       [INPUT_FILE]

positional arguments:
  INPUT_FILE            Filename of the input file (default is stdin)

options:
  -h, --help            show this help message and exit
  --output OUTPUT       Optional output filename for saving the result (default is stdout).
  --tab TAB
  -R ROBO, --ROBO ROBO
  -P POLY, --POLY POLY
  --units UNITS
  --encoding CHAR_ENCODE
  --layer_option LAYER_OPTION
  --layer_name LAYER_NAME
  --id IDS              id attribute of object to manipulate
  --selected-nodes SELECTED_NODES
                        id:subpath:position of selected nodes, if any

But it does not say what the valid values are for the parameters. ROBO and POLY must both be either True or False.

E.g.:

$ dxf_outlines.py --output foo.dxf -R=True origin.svg

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.