Loading
polymaker

Inkscape OpenSCAD DXF Export

by polymaker Dec 3, 2011
Download All Files

Thing Apps Enabled

Please Login to Comment

Thanks for this super super helpfull tool!!!! :D It was my greatest finding on thingiverse in a very long time :)

One question: What is the default document size? My objects are misplaced when I use the default page so I think there might be different page size in US / EU etc.

Your note on this subject says (but you do not give your default document size):
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.

Move your drawing in the bottom left corner of the page in InkScape, so the centre of your drawing align with the corner of the page (3/4 of the drawing will be outside the drawing area). When you import in in OpenSCAD, your drawing is centred at [0, 0].

For perfect alignment, select your drawing in InkScape, change the X, Y coordinates manually to match half the width and height.
Example:
X: -50, Y: -20, W: 100, H: 40

How did I not notice this before? Thank you so much for making this!

Thanks for sharing the library. It is very useful.
For total_width and total_height, dxf_dim appears to work fine.
But I was having trouble centering my image, is there any way to capture the offset? I was able to parse them from the .dxf output directly (again, thanks for putting this in there), but I can't figure out how to get scad to provide it for me. Any ideas what I'm doing wrong?>

For instance, my image has these dimensions:
dxf_dim_x = [ 67.792165 , 745.029541 ];
dxf_dim_y = [ 63.914300 , 700.749932 ];
And dxf_dim:
tw = dxf_dim(file="foo.dxf", name="total_width");
th = dxf_dim(file="foo.dxf", name="total_height");
tw = 677.237
th = 636.836

This provides the xmax - xmin and ymax-ymin values. Is there a way to modify your extension to make xmin and ymin to dxf_dim within openscad?

Thanks.

@Levi8than Great idea! I have to be honest, I don't completely understand how adding these dimensions works, but I think I may have managed it. Please replace your openscad_dxf.py file with this updated version and test it out:

https://raw.githubusercontent.com/brad/Inkscape-OpenSCAD-DXF-Export/min_max_x_y/openscad_dxf/openscad_dxf.py

I attempted to add "total_minx", "total_maxx", "total_miny" and "total_maxy" as well as similar dims for each layer named "_minx" and so on. So you should be able to center it like so:

tw = dxf_dim(file="foo.dxf", name="total_width");
th = dxf_dim(file="foo.dxf", name="total_height");
mx = dxf_dim(file="foo.dxf", name="total_minx");
my = dxf_dim(file="foo.dxf", name="total_miny");

translate([-mx-tw/2, -my-th/2])
import("foo.dxf");

Please let me know if it works for you.
Thanks!

That works perfectly.
Thanks for being so fast.

Thanks for testing it! I've added an new zip with the update

Despite the error the extension did generate an .dxf file that contains an object but in wrong units (mostly to small).

I have fixed the error, which was due to a change in inkscape and uploaded a remixed version

see http://www.thingiverse.com/thing:812590

Inkscape OpenSCAD DXF Export - update for Inkscape V0.91

Thank you @chris_cki. I have fixed the problem in V2

Does this work with Inkscape 0.91? I get the following error:

Traceback (most recent call last):
  File "openscad_dxf.py", line 231, in 
    if __name__ == '__main__': OpenSCADDXFEffect().affect()
  File "C:\Program Files\Inkscape\share\extensions\inkex.py", line 268, in affect
    self.effect()
  File "openscad_dxf.py", line 143, in effect
    h = inkex.unittouu(self.document.getroot().xpath('@height',namespaces=inkex.NSS)[0])
AttributeError: 'module' object has no attribute 'unittouu'

Hi there, I'm getting the same error as ppcMacGyver below. I've just installed a fresh new version of Inkscape v0.48, and the your code from github. Any ideas on how to fix?

Traceback (most recent call last): File "openscad_dxf.py", line 231, in if name == 'main': OpenSCADDXFEffect().affect() File "C:\Program Files (x86)\Inkscape\share\extensions\inkex.py", line 221, in affect self.effect() File "openscad_dxf.py", line 199, in effect [self.global_dims['minX'], self.global_dims['maxX']]) File "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

Please disregard my question. I discovered the problem: me. I loaded the file in inkscape, but never bothered to trace the bitmap. After doing this, I was then able to save as dfx and import into openscad. Thanks for the extension.

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!

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.pyopenscad_dxf.py", line 231, in <module>
if name == 'main': OpenSCADDXFEffect().affect()
File "C:\Program Files\Inkscape\share\extensions\http://inkex.pyinkex.py", line 215, in affect
self.effect()
File "http://openscad_dxf.pyopenscad_dxf.py", line 199, in effect
[self.global_dims['minX'], self.global_dims['maxX']])
File "http://openscad_dxf.pyopenscad_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>

Comments deleted.

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.pyopenscad_dxf.py", line 231, in <module>

    if name == 'main': OpenSCADDXFEffect().affect()

  File "C:\Program Files (x86)\Inkscape\share\extensions\http://inkex.pyinkex.py", line 215, in affect

    self.effect()

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

    object2path.ObjectToPath.effect(self)

  File "C:\Program Files (x86)\Inkscape\share\extensions\http://object2path.pyobject2path.py", line 50, in effect

    self.call_inkscape("ObjectToPath", objects)

  File "C:\Program Files (x86)\Inkscape\share\extensions\http://inkinkex.pyinkinkex.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.pyopenscad_dxf.py", line 231, in
&
lt;module
&
gt;

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

File "C:\Program Files\Inkscape\share\extensions\http://inkex.pyinkex.py", line 215, in affect

self.effect()

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

object2path.ObjectToPath.effect(self)

File "C:\Program Files\Inkscape\share\exten
sions\http://object2path.pyobject2path.py", line 50, in effect

self.call_inkscape("ObjectToPath", objects)

File "C:\Program Files\Inkscape\share\extensions\http://inkinkex.pyinkinkex.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.pyopenscad_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!