Easy DXF to SVG on macOS using Inkscape command line

I got tired of firing up Inkscape to convert DXF to SVG, so I figured out how to do it from the command line. The obvious method of using the inkscape command line script doesn’t work because DXF input is an extension and it can’t find your files for some reason.

You need to run the python input extension directly. First, you must get the lxml library installed. You can use easy_install as outlined in that link, but I prefer pip. Unfortunately, then you need pip installed. I prefer to use the python from Homebrew (install homebrew, then “brew install python”), in which case you will be using “python2” and “pip2” below, and omitting “sudo”.

So, get the lxml library, however you want:

sudo pip install lxml

then to convert a file:

python /Applications/Inkscape.app/Contents/Resources/share/inkscape/extensions/dxf_input.py --scale=25.4 file.dxf > file.svg

You can automate this with Automator by creating a new Folder Action:

This lets me save DXF files to a ConvertDXF folder on my desktop, and an SVG file appears within the SVG subfolder immediately.

Leave out the “–scale=25.4” if you work in mm. You can also try --scalemethod=file to read the scale automatically, but my workflow from Fusion360 outputs DXF files with no explicit scale.

29 Likes

I’m gonna move this to the Tips Tricks and Tutorials category @jsc . Great write-up. :grinning::+1:

1 Like

This has stopped working for me yesterday. I tracked down the issue to a missing xmlns declaration in the generated SVG. It can be fixed by making your own copy of that file and adding

import sys
sys.path.append('/Applications/Inkscape.app/Contents/Resources/share/inkscape/extensions')

above the import line at the top of the file, and searching for "<svg " and adding

xmlns="http://www.w3.org/2000/svg" 

after it.

However, I just discovered a bug in the Inkscape DXF import where certain 180 degree arcs will become flipped around. I looked for alternative conversion methods, and everything was either too arcane to bother with or had the same issue, until I came across this one: https://cloudconvert.com/dxf-to-svg

It works, is easy, and will give you a certain number of free conversions per day (25 maximum).

9 Likes

shouldn’t that be:
xmlns=“SVG namespace” ?

2 Likes

Like I said, 2000.

Or maybe it accepts a very early version of the spec. VVV.VIII.ORG/CC/SVG in the original Latin.

Thank you for the correction.

4 Likes

i can’t get this to work, keep getting Zero byte files. its not the workflow because when i run the commands personally i get the sam result.

Yeah, I’m going to have to say, don’t use this. Not because of zero-byte files, which I never ran into, but because it turns out the SVG you get from running that file is missing a bunch of stuff which running it from within Inkscape fills in. So uploading the results to Glowforge occasionally results in a stuck processing dialog.

I’ve found that it is best to do some manual processing on DXF to SVG converted files, in any case. Like, all the path segments come in as individual paths, so I like to select everything that should be cut in a single operation and combine them, so you don’t get strange cutting behavior where it jumps around and cuts things out of order.

1 Like

Anyone else notice the double cut from a Fusion 360 sketch saved as a DXF, and converted into an SVG via Inkscape ?

Turns out that Fusion 360 by default will add in a second layer with a duplicate path in the DXF which gets passed through to the process to the SVG. And the GF dutifully does what it was told and cuts the line twice (one for each path).

(Note: it could be my 360 workflow, creating a sketch that is a projection of a body)

Solution - turn off a setting in 360 as shown here:
https://forums.autodesk.com/t5/fusion-360-design-validate/why-does-export-as-dxf-in-sketch-double-all-paths/td-p/6872831
And remake your sketches
Removing the duplicate should both save time, but also reduce the risk of cutting the cerf again - and I saw some “interesting” flare ups while watching this happen.

I verified the issue looking at the SVG before and after (yes, it is an text/xml document :slight_smile:

2 Likes

Thanks for this scripting idea…hopefully I can get something similar working in Linux.

I’ve been happily cutting SVG files from Inkscape, but this morning I went to use OpenSCAD to generate a more “functional” / “dimensional” file and was very surprised to find that DXF was not natively supported by the Glowforge import pipeline.

I found a thread from November of last year that said “The DXF format is going to be delayed, but is in the hopper for future development.”

Sure, I can import/export from Inkscape manually to make an SVG, but this is a pain, especially when cutting multiple trials with very small changes to get an exact fit. I hope they get DXF support integrated soon.

1 Like

There is also a workaround for this. Create a new construction plane on a surface instead of creating a sketch. Then create a new sketch on the construction plane.

I use a mix of the two techniques depending on my results.