I started using Inkscape, a sweet open-source vector graphics program, to produce (and/or steal from the internet and convert) designs suitable for carving on the CNC as Inkscape has a plugin to export the file as a .DXF. Converting some files, I discovered the current export script does not correctly handle all types of transforms, so some parts of the file may export out-of-proportion to each other or in strange size units regardless of the drawing units of the original drawing (Inkscape’s internal drawing unit is apparently equal to 1/90 of an inch, wait, wtf?). Also, if the drawing contains curved (Bezier) lines, these will be exported more or less as-is (DXF splines) and many free/cheap/itch-scratch-ware programs will not handle the resulting file (since the ‘correct’ representation or interpretation of splines is never disclosed in the published DXF file specifications, so everyone kind of does them in their own way, with less-than-stellar results).
Bob Cook noticed these limitations and updated the script to fix many of the ‘unusual transforms’ scaling issues, and convert Beziers to standard polylines that any program will import. It also adds some support for layers, including special ‘drill’ layers whose drawing objects will be output as single points (no lines) for hole drilling.
In theory, the layer support as he implemented it ought to work (it’s correct and in conformance with the DXF spec, which allows drawing objects to be assigned to arbitrarily-named layers throughout the file). In practice, many of the same free/OSS, low-cost and weekend-warrior tools do not handle this any better than splines. I dug up a copy of the DXF spec, played around a bit and found that these programs expect all layers to be formally declared in a DXF LAYER table in the header section of the file before use. So here is an update to the export script that generates a proper LAYER table, allowing a wider variety of toolpath generating programs to import them correctly. So far it has been tested with ACE Converter and CamBam and seems to work well, but as always this is a quick n dirty, not exhaustively tested script and there is no lifeguard on duty. (Inspect the imported files for problems before commanding your big machine to cut them!)
Better Better DXF Output for Inkscape
Just unzip into your \Inkskape\share\extensions directory. Note that the updated ’simpletransforms.py’ replaces an existing file.
Note: There is still an outstanding issue with Grouped objects in Inkscape being exported with incorrect size. As I understand it (assuming the document structure sent to export scripts is substantially an SVG file), transforms are applied at the Group level, which is sort of a container that has the actual drawing objects (and possibly further nested groups) as its children. Guessing that to handle this correctly, rather than looking for transforms at the node itself, it must also maintain a stack of transforms that have been applied at the node’s parent level, and parent’s parent, etc. For now, it is an easy workaround to ungroup everything before export. Maybe someone with freetime can update this and release it as ‘Better Better Better DXF Output’ :-) (b3dxf?)
March 15th, 2009 at 7:11 am
THX a lot for the script! Just what i needed to design some simple forms for CNC with CFK-platters. Hopefully it will work out as i plan it :-)
CU
Markus
April 19th, 2009 at 8:25 pm
Very good, thanks for your addition! I am just getting into inkscape and noticed that all of the DXF lines are output with the same color. The DXF palette has 256 possible colors, perhaps there is a way to export to DXF using the best match of a palette color?
April 23rd, 2009 at 9:36 pm
Thanks very much for the script! It works as expected. Unlike the 0.46 built-in “Desktop Cutting Plotter DXF” output which does not work (gives me broken lines covering only about half of my path, for some reason.)
July 30th, 2009 at 10:52 pm
The 0.47pre1 has some DXF improvements, does this script include those changes? Will this be submitted as a patch to inkscape?
August 18th, 2009 at 11:15 pm
I tried this extension with mixed results. Tried opening the exported DXF in 3 CAD editors/viewers – Result
Autodesk AutoCAD 2002 LT – Fatal Error!
Autodesk DWG TrueView 2008 – Fatal Error!
DWGeditor 2009 (IntelliCAD engine) – Opened
However, none of the above CAD programs opened the original Inkscape DXF so the result is still better!
August 18th, 2009 at 11:36 pm
Further to my previous message…
I converted a text to vector path, which I suppose must be grouped. Maybe that’s the problem. I tried again with some simple geometry (squares, circles), it seems no problem.
September 29th, 2009 at 12:40 am
I have used this and it works great!! I have hundreds of svg files to convert. Is there anyway I can do this in a script outside of inkscape?
November 6th, 2009 at 1:37 pm
I have tried using this and opening the .dxf file in AutoCAD R2008, but I get this message on open:
Missing Default entry 0 in SymbolTable:LAYER
Invalid or incomplete DXF input — drawing discarded.
December 29th, 2009 at 2:25 am
I was having broken lines in the dxf exports and Better DXF export fixed this nasty problem.
Thanks a lot.
July 6th, 2010 at 12:12 am
I was getting errors using Ubuntu 8.10 and Inkscape 0.47–these were resolved by replacing xpath(path,inkex.NSS) with xpath(path,namespaces = inkex.NSS) in b2_dxf_outlines.py
July 18th, 2010 at 3:17 pm
I’m using Better DXF from Bob Cook’s site, and quickly noticed a problem. Inkscape 0.46 (on Ubuntu 8.10) assigns layer names such as “Layer 1″ by default, with a space in the name. Better DXF takes these names unchanged, and when I try to import the DXF file into AutoCAD 14, it fails. I’ve been going through the DXF files with a text editor and performing a global search-and-replace to change all “Layer xx” type names to “LAYERXX” or “LAYER_XX” names, and then AutoCAD is happy. Another way to do it is to change the layer names in Inkscape, before exporting with Better DXF, but I don’t always remember to do it. The Python script should be tweaked to change names to all-uppercase and strip embedded spaces in layer names or substitute the underscore character during export from Inkscape, before building the layer table, thus avoiding this aggravation. Some others have noted AutoCAD DXF import problems here, and that may have been the cause.
August 24th, 2010 at 3:33 pm
I noticed some of the limitations of this tool and extended it to create DXF Export for Inkscape. It allows color output, fixes the layer names, runs correctly on more systems, outputs in inches, and shortens the length of the segments.