DXF export from Inkscape
I’ve been using SheetCam to generate g-code for my CNC mill and so far I’m pretty happy with it. It probably isn’t the top-of-the-line CAM software available but its (so far) doing the job for me. SheetCam consumes DXF files – a vector format originated by AutoCad. So I needed something that would generate DXF and I wanted something simple. Someday I’ll probably want to invest in a high-end CAD program but for now I really wanted something very simple and very cheap or even free. I immediately thought of Inkscape, the free vector drawing program for Windows and Linux.
I’ve been using Inkscape for other projects for quite a while and I had noticed it would export to DXF so I thought I was all set: just draw my part outlines in Inkscape and export a file for SheetCam. My first experiment with one simple path object was successful so I optimistically figured everything else would simply work. Oh that would have been too easy…
First I discovered that the Inkscape DXF export doesn’t support layers. It also doesn’t support objects other than paths (Inkscape treats rectangles and circles and such as objects other than basic paths) so my exported files were mostly blank. Although figuring out these problems took quite a while because I (naively) thought all of this would simply work so I didn’t bother to research it very deeply from the start.
So I started to dig into the problem in the Inkscape bug database and sure enough there were two additional problems highlighted:
- the DXF export did not support objects with the “transform” attribute; this meant that sometimes objects were simply in the wrong position and it was hard to know when it could happen without exceptionally detailed proof-reading
- the DXF export didn’t produce “usable” DXF for at least some readers; SheetCam wasn’t mentioned by name but it seemed that maybe it wasn’t an uncommon problem
Through my own experimentation I found that SheetCam didn’t import the SPLINE objects from the DXF correctly (they were highly distorted). I will say that the SheetCam support was very helpful in explaining the problem as well as making a couple of useful suggestions that I could do inside Inkscape manually.
It worked, but I really wanted an automated solution to as many of these problems as possible.
Fortunately I discovered that Inkscape’s export module is written in Python and I could easily modify it. So I rolled up my sleeves and made my own version of the DXF export module that solves my problems. I started with the updated version from that Inkscape bug but added logic to save the layer identifier for each object and (using a separate Inkscape module) convert cubic paths into line segments (flattening) automatically. I also fixed up the problem with the “transform” attribute. It still doesn’t deal with arbitrary object types but that is pretty easy to solve (Select All, Convert Objects to Paths).
So now its back to the design stage for my next milling project!
For anyone who is interested, visit this page to download all of the required files.
Pretty interesting blog post. I’m an engineer (in real life) and I have been using Adobe Illustrator as a bridge between Inkscape and Autodesk Inventor (or AutoCAD). Adobe works well with Autodesk products. That’s basically why I keep it around. I would like to try your extension and see if it works for me.
Thank-you!
🙂
Comment by heathenx — May 4, 2008 @ 4:45 amI can’t seem to get this to work. Load the following file into Inkscape 0.46: http://www.britishideas.com/temp1533/heart2.svg then save as “Better DXF”. If you look at the DXF file generated the image is now upside down.
Any ideas?
Andy
Comment by Andy — June 29, 2008 @ 1:23 pmAndy: I was able to reproduce the problem, and it looks like there is something unique about that SVG file that the DXF export code can’t cope with. The objects themselves were ok, but seemingly subject to some sort of view transformation. I was able to get a correct version in Inkscape by copying all objects (Edit > Select All in All Layers, Edit > Copy) then paste into a new document (File > New > Default, Edit > Paste) then moving the group onto the document. After that, I was able to save DXF just fine.
Comment by Bob — June 29, 2008 @ 2:27 pm[…] go to this post on BobandEileen.com, right click on the link to “dxf_templates.py” and save it in C:Program […]
Pingback by Using Inkscape for CNC Designs and DXFs | Interesting Tech Projects | BritishIdeas — September 4, 2008 @ 9:44 pm