Loading

Inkscape OpenSCAD DXF Export

by polymaker, published

Inkscape OpenSCAD DXF Export by polymaker Dec 3, 2011

Description

Most of us have our favorite tools. One of mine is Inkscape. I'm no pro but I've been able to do what I need with it. Another of my favorites is OpenSCAD. The purpose of this thing is to make it easier to take something from Inkscape and use it in OpenSCAD.

The current steps you need to take to turn an SVG into an OpenSCAD usable DXF are the following:

  1. Convert all objects to paths
  2. Add extra points to paths
  3. Convert paths to lines
  4. Export to DXF

After all that you may use your SVG design in OpenSCAD, but then if you want to edit your design you are faced with two equally unpalatable options: edit the original design and go through the steps again, or edit the DXF directly.

I had had enough and set out to automate that process. I took all the best parts of at least 3 other DXF output extensions (I lost count!) and added automation for the steps listed above. With this Inkscape extension, you can edit/save your design and simply "Save a Copy As" to DXF whenever you want to try it in OpenSCAD. It is a lot smoother that way.

Supposedly it exports color to the dxf as well but I don't know if that's supported in openscad.

NOTE: If you change the size of the document in Inkscape the exported DXF will have misplaced objects. A workaround for this is to recreate all layers after resizing the document. I know, painful, but once you have the size worked out it's not bad.

BONUS FEATURE: The extension automatically adds dimensions to the DXF: layer_name_width and layer_name_height for each layer and total_width and total_height. The dimensions can be accessed using the built-in dxf_dim command. Ex.:

total_width = dxf_dim(file = "openscaddxf.dxf", name = "total_width");

Three fairly small provisos:

  • It's fairly slow because it has to launch a new inkscape instance to convert the objects to paths. It's not a pretty solution, but I believe it's the only way to do it at the moment.
  • Doesn't work with groups. You will need to ungroup everything before exporting
  • Doesn't work with intersecting lines. This will cause either the offending objects to disappear or everything will appear outlined instead of filled in.

Repo is here: https://github.com/brad/Inkscape-OpenSCAD-DXF-Export

Recent Comments

view all
THANK YOU!!!!!!!!!!!!
Happy to help!
You really made my day with this one. . . It turned what I thought was going to be a long project into a quick and simple one. Now I have a real process flow for turning a line drawing into an STL. I can't thank you enough!

More from 2D Art

view more

Liked By

view all

License

GNU - GPL
Inkscape OpenSCAD DXF Export by polymaker is licensed under the GNU - GPL license.

Give a Shout Out

If you print this Thing and display it in public proudly give attribution by printing and displaying this tag. Print Thing Tag

Instructions

Copy the .py and .inx files (the zip contains these files) to your Inkscape extensions folder: http://wiki.inkscape.org/wiki/index.php/Script_extensions#Installing

Create some objects in Inkscape and save them directly to a DXF that OpenSCAD can use! The included STL is an extruded DXF generated from pure Inkscape objects.

Enjoy!

THANK YOU!!!!!!!!!!!!
You really made my day with this one. . . It turned what I thought was going to be a long project into a quick and simple one. Now I have a real process flow for turning a line drawing into an STL. I can't thank you enough!
Happy to help!
Simply wanted to add my thanks to all of the other's. This was very helpful!
wow, you saved me so much trouble. Thank you! This works like a miracle!
I'm so glad it helped
Thank you thank you thank you!!!

This is amazing! Great work!
I am receiving errors when i try to save. I have uninstalled Inkscape, started fresh with a new download and placed the files in the shared folder.

any ideas?

Traceback (most recent call last):
File "http://openscad_dxf.py", line 231, in <module>
if __name__ == '__main__': OpenSCADDXFEffect().affect()
File "C:Program FilesInkscapeshareextensionshttp://inkex.py", line 215, in affect
self.effect()
File "http://openscad_dxf.py", line 199, in effect
[self.global_dims['minX'], self.global_dims['maxX']])
File "http://openscad_dxf.py", line 126, in dxf_add_dimension
('13', '%f' % (x[0] if x is not None else 0.0)),
TypeError: float argument required, not NoneType</module>
Please note: If you already installed "better dxf" or "better better dxf" or what else is out there you have to reinstall your inkscape application, because these plugins overwrite an inkscape-file that breaks this plugin.
I've uploaded a new version that should automatically work for Mac users, and I added some error handling for problems that have been posted in the past.
The path on Mac OS X is: '/Applications/Inkscape.app/Contents/Resources/bin/inkscape'

Seems to be working!
 Thanks! I have updated the package and it should now would on Mac without changing anything.
I get exactly the same error message as tim1986 below:-

Traceback (most recent call last):

  File "http://openscad_dxf.py", line 231, in <module>

    if __name__ == '__main__': OpenSCADDXFEffect().affect()

  File "C:Program Files (x86)Inkscapeshareextensionshttp://inkex.py", line 215, in affect

    self.effect()

  File "http://openscad_dxf.py", line 138, in effect

    object2path.ObjectToPath.effect(self)

  File "C:Program Files (x86)Inkscapeshareextensionshttp://object2path.py", line 50, in effect

    self.call_inkscape("ObjectToPath", objects)

  File "C:Program Files (x86)Inkscapeshareextensionshttp://inkinkex.py", line 156, in call_inkscape

    cmd += " --select="+id

TypeError: cannot concatenate 'str' and 'NoneType' objects

Does anyone know what to do to fix this error message ?
</module>
 I have added error handling to fix this problem in the new package if you would like to try again.
 The python error means that the ID for that SVG is blank, but the script expects all objects to have IDs. Would you mind creating an issue on the Github repository and attach the SVG file so I can debug?
I cannot get this extension to work. I get this error:

Traceback (most recent call last):

File "http://openscad_dxf.py", line 231, in
&
lt;module
&
gt;

if __name__ == '__main__': OpenSCADDXFEffect().affect()

File "C:Program FilesInkscapeshareextensionshttp://inkex.py", line 215, in affect

self.effect()

File "http://openscad_dxf.py", line 138, in effect

object2path.ObjectToPath.effect(self)

File "C:Program FilesInkscapeshareexten
sionshttp://object2path.py", line 50, in effect

self.call_inkscape("ObjectToPath", objects)

File "C:Program FilesInkscapeshareextensionshttp://inkinkex.py", line 156, in call_inkscape

cmd += " --select="+id

TypeError: cannot concatenate 'str' and 'NoneType' objects

How can I make this work?
 Tim, I've added error handling to fix this in the latest version if you would like to try it again.
I don't know, maybe there's something wrong with the SVG and some objects don't have ids? Maybe try and copy/paste everything to a new document?
This worked like a charm with Inkscape 0.48. Thank you! :)

FYI one thing I learned is that 0,0 (X,Y) is treated as the lower left corner of your layout in Inkscape which is important if one uses the rotate_extrude() function for creating rotated shapes using a DXF in OpenSCAD.
Oh, you do need to upgrade to 0.48 if you haven't already as this doesn't work in Inkscape 0.47... =-O
Getting this error when I try to export

"Traceback (most recent call last):

File "http://openscad_dxf.py", line 29, in
&
lt;module
&
gt;

from collections import OrderedDict

ImportError: cannot import name OrderedDict
"

When I try to convert your openscaddxf.svg to dxf
OrderedDict was added in Python 2.7. No matter, I accidentally left that unused import in there. I have removed it from the zip and fixed the problem in the repository. Thanks for trying it out!
Fixed it, thanks!
Top