2D dxf line import?


Is there a library or method for importing a 2d dxf file into OF?
i.e. a dxf file of layers and lines, polylines, etc?

In hope

If you can save it out as SVG this addon can load SVG with a lot of control over how you access the elements.


Hi Theo

Thanks for the reply. Yes, I know svgLoader, actually I’ve used it for long enough that I’ve tailored it a bit to suit my needs… (I removed the fact that a line of less than 1 width seems to not import, for instance).

It does exactly what I want (the group/layer name extraction is ideal) but it does mean that the plan drawings that I use it to load have to be converted from dxf to svg via illustrator first.

Hence I was wondering about the feasibility of having a native dxf import into an OF app. It would take out the illustrator step…


[edit, to clarify, the softwares I use to draw the plans often don’t have an svg export, just dxf]

Seems this is a ‘no’ then?

there’s surely some dxf parser libraries you can use. a quick search gives me https://www.ribbonsoft.com/en/dxflib-downloads which is gpl so you would have to release your application as gpl as well if you distribute it but they also seem to have a commercial license not sure under what terms

Ok, this would be new to me, using an external library… but I’ll give it a go, see what I can do.

Hmmm, this initially looked promising:

but I’m getting an apple linker error having built a little testApp:

Undefined symbols for architecture x86_64: “_iconv_open, _iconv, _iconv_close"

my testApp file is here and my poor attempt at an addon file is here

Out of my depth here I think

Hi @Sam_McElhinney_io I think is very cool that you are working on a dxf ofxAddon. I was just about to start a project where I need it and was thinking of developing the same.

So far, I haven’t started yet, but have you have any progress since then?

yes, I did actually get this done. Not as a proper addOn, but as one that works for me. I can share where I got to, if others want to make it into a proper add-on?

I got as far as full support for auto cad dxf and dwg up to auto cad 2019, including spline etc reconstruction. It is just a messy hack of the available libraries. I’m sure someone else could easily do a better job at cleaning it up!

Hi @Sam_McElhinney_io,

If you can share it in the forum that would already be amazing. I might put also some effort and re-write it to have it as an add-on. I think it would be very helpful.

ok, if anyone wants to run with this, I’d appreciate a more ‘pro’ look at what I’ve done!
I don’t have a GitHub, so here’s three dropbox links:

Basic demo sketch:

My hacky dxf add-on:

an adapted version of ofxCurve add-on (needed to rebuild splines, etc):

From what I remember I’d solved implementation of groups, cells/symbols, layers and all 2d line types.

It opens all dxfs and dwg formats uo to 2019 (haven’t checked 2020, but Autocad has a nasty habit of making tiny changes in the internal labelling systems every year, for no reason other than to make people update IMO).

It produces a set of 2d line objects in the final OF Drawing (all polylines I think)

Comments and or improvements extremely welcome.

Amazing work. I’m already starting to compile it on Windows. Still getting some errors, but I’ll get back with some feedback, once I get into it.