DXF-Importer - release

Wiki page for newest version…

Just let us know when you are ready to have it committed, posting here or the bf-python list is fine…

LetterRip

It is ready now. If you give me just a minute I’ll even comment out some debugging I forgot to turn off yesterday :wink:

Looks like I might have some time today so I’m going to have a look at 3dfaces. bcon3 will last at least a week right? I’ll update here if there are any added features before the bugfix freeze.

Edit: Oops, I accidentally just added 3dface support… That was really too easy. Currently 3dfaces import as just that - individual 3d faces. In the dxf file there is no way to say ‘this face goes with this face and that face’. Right now if you wanted to use an object made of faces you would need to make sure your objects faces are all the same layer, then in Blender select similar by layer > alt-j to join > remove doubles > ctrl-n recalculate normals outside…

Looking at the docs it seems there aren’t any other 3d face type entities in the dxf format - everything else is under “proprietary format data”. I think I’m going to try to implement lights in the next couple of days (to add to the list of supported features no one uses :)) then dig into the sat format. I have a feeling that will basically halt useful development updates for the foreseeable future.

Ok, just tested your dxf import script. I’ve tried 3 2D DXF’s that import using the existing inbuilt DXF importer everyone goes on about as being usless. When i try to import using this new script, these are the errors:

Checking for installed Python… got it!
Traceback (most recent call last):
File “<string>”, line 213, in main
File “<string>”, line 305, in drawDrawing
File “<string>”, line 317, in drawEntities
File “<string>”, line 863, in drawBlocks
File “<string>”, line 155, in call
File “<string>”, line 164, in add
File “<string>”, line 317, in drawEntities
File “<string>”, line 519, in drawTexts
TypeError: expected a tuple of 3 floats
Traceback (most recent call last):
File “<string>”, line 213, in main
File “<string>”, line 302, in drawDrawing
File “<string>”, line 184, in init
File “<string>”, line 290, in getBlocks
AttributeError: Object instance has no attribute ‘blocks’
Traceback (most recent call last):
File “<string>”, line 213, in main
File “<string>”, line 302, in drawDrawing
File “<string>”, line 181, in init
File “<string>”, line 282, in getLayers
UnboundLocalError: local variable ‘layers’ referenced before assignment

As mentioned previously, the three DXF’s i tested all open perfectly with the in built DXF importer. They were originally AutoCAD dwgs, exported from AutoCAD as DXF, imported and exported through Accutrans as DXF and that solves 2D DXF import, even easier opening the autocad dxf’s up in OpenOffice rather than using accutrans and saving as SVG then importing into blender works flawlessly too. (thanks ne0n and jms).

The SVG route gives you the added bonus of them being imported as curves.

Hopefully though this script will be better than the existing solutions. One plus for me would be that edges import with a rotation value relative to blenders coordinate system.

Thanks so far but it doesn’t seem to work too well with what i’ve tried.

works better than last one but I’m getting thses errors on linux:
http://afecelis.gdlib.net/Blender/dxf_err.jpg

afecelis: Hi there, yes i’ve had that one as well about ‘append’ I’m also on Linux but i’d hope that didn’t have anything to do with it, either way i don’t think the script fit for commiting for the upcoming release YET, hope it will improve, the script is far from workable and will only add to the confusion with DXF import.

iv renamed .append() to .link() and remove to .unlink(), after discussion on IRC.
Sorry about the inconvenience. maybe I should keep append and remove for backwards compat.

For future bug reports - In order to do anything about bugs I need not only the traceback from the console, but also the offending dxf file, and information about what Blender version you are using (OS shouldn’t matter).

This is probably my fault though, I was still testing under 2.42a instead of the latest CVS. I should have known things had changed just from reading the mailing list!

Since this is meant to be bundled with the next version I suppose I should use the nifty new object visibility functions? I think they line up pretty well with display off/frozen/non-plot. There is no way to toggle them in a ‘layer’ currently though…

Edit: Yeah, I think it would be a good idea to leave group append/remove. As it is I have to choose to support either B2.42 or cvs. Also does link/unlink make sense? Are groups data-blocks or just lists? Even if they are data-blocks it makes more sense to treat them as a list from the Python perspective. Also is there a place where the cvs-Bpy docs are online? Guessing sucks, introspection is a pain with Blender’s non-interactive Python shell, and I don’t feel like trying to compile Blender right now. Maybe some nice person could post Bpy updates on graphicall.org along with all the cvs builds?

During my tries to import some DXFs, it was always line 755, causing a lockup:

step = delta/pieces

“pieces” is not checked against being 0, which indeed is possible if “end” equals “start”
(6 lines above).

After some little modifications, your script works a little better than the included one, but a lot of stuff still does not work (aka: import) correctly.
But, except for the above div by zero, it did not crash. Nice.

cheers
AS

status update? does it work in current CVS now?

LetterRip

This is a wonderful script, I use it since a long time now. The amazing thing is that when you import very large dxf files, you see that blender handles without problem enormous 2d drawings full of lines and texts.

Kitsu: the open design alliance libraries you mentioned are already used in a couple of open-source projects, like lxviewer. Their license system is a bit weird, to be polite, last time I checked, every end-user of the libs needed to send a FAX to their US offices, to “ask for permission” to use it…

status update? does it work in current CVS now?

LetterRip

Just downloaded Release2.zip from Kitsu’s site.

First attempt. AutoCAD R12 DXF.

Absolute silence, no crash but no import and no feedback whatsoever. Good sign?

Second attempt, different AutoCAD R12 DXF:

Console error:

Traceback (most recent call last):
File “<string>”, line 213, in main
File “<string>”, line 302, in drawDrawing
File “<string>”, line 181, in init
File “<string>”, line 282, in getLayers
UnboundLocalError: local variable ‘layers’ referenced before assignment

I’m going to try a few more, but otherwise forget it, quicker and easier just to open in openoffice, export as SVG and import into blender (thanks Ne0n/jms) or use accutrans to convert to a DXF that the old hardcoded DXF import handles perfectly 100% every time going back to 2.37a and probably before that.

Biggest issue i have even when you’ve got an DXF imported correctly is that if you create faces from the import straight off the normals are all over the place and you get some nasty mixed up normals/shading/meshes, if you extrude first and then create faces from the same edges/vertices there’s no problem with normals. This only started happening after 2.37a. Consequently i don’t use any version of blender after 2.37a for modelling from DXF imports because something changed for the worst back then, i think i remember seeing the change appear on the mailing list, something to do with the way edges are interpreted / scored / null, i don’t know i’m no programmer. But the bug still exists even now.

Done some more tests, not one import yet, not even the two files exported from Accutrans that import with the hardcoded script and BANG! the last attempt crashed blender outright and gave a Backtrace. below, I give up for now.

Traceback (most recent call last):
File “<string>”, line 213, in main
File “<string>”, line 305, in drawDrawing
File “<string>”, line 317, in drawEntities
File “<string>”, line 705, in drawArcs
TypeError: expected a tuple of 3 floats

Traceback (most recent call last):
File “<string>”, line 213, in main
File “<string>”, line 305, in drawDrawing
File “<string>”, line 317, in drawEntities
File “<string>”, line 357, in drawLines
AttributeError: ‘Blender GroupObSeq’ object has no attribute ‘append’

Traceback (most recent call last):
File “<string>”, line 213, in main
File “<string>”, line 302, in drawDrawing
File “<string>”, line 184, in init
File “<string>”, line 290, in getBlocks
AttributeError: Object instance has no attribute ‘blocks’

AttributeError: Object instance has no attribute ‘blocks’
*** glibc detected *** /home/yellow/blender-Dec-CVS/install/linux2/blender: corr
upted double-linked list: 0x0000000001edc400 ***
======= Backtrace: =========
/lib/libc.so.6[0x2b5b19306b37]
/lib/libc.so.6[0x2b5b193084ab]
/lib/libc.so.6(__libc_free+0x84)[0x2b5b193088b4]
/usr/lib/libpython2.4.so.1.0[0x2b5b1765cd0e]
/usr/lib/libpython2.4.so.1.0[0x2b5b17668adb]
/usr/lib/libpython2.4.so.1.0[0x2b5b17648b23]
/usr/lib/libpython2.4.so.1.0[0x2b5b17668adb]
/usr/lib/libpython2.4.so.1.0[0x2b5b17648b23]
/usr/lib/libpython2.4.so.1.0[0x2b5b17656ffd]
/usr/lib/libpython2.4.so.1.0[0x2b5b176cc68d]
/usr/lib/libpython2.4.so.1.0[0x2b5b17666d87]
/usr/lib/libpython2.4.so.1.0(PyDict_SetItem+0x79)[0x2b5b17669199]
/usr/lib/libpython2.4.so.1.0(PyDict_SetItemString+0x4b)[0x2b5b1766929b]
/usr/lib/libpython2.4.so.1.0(PyErr_PrintEx+0x19e)[0x2b5b176c886e]
/home/yellow/blender-Dec-CVS/install/linux2/blender(BPY_free_finished_script+0x1
8)[0x6e3aa8]
/home/yellow/blender-Dec-CVS/install/linux2/blender(winqreadscriptspace+0x71)[0x
60de41]
/home/yellow/blender-Dec-CVS/install/linux2/blender(screenmain+0x529)[0x4ca3b9]
/home/yellow/blender-Dec-CVS/install/linux2/blender(main+0x33d)[0x4926bd]
/lib/libc.so.6(__libc_start_main+0xf4)[0x2b5b192b70c4]
/home/yellow/blender-Dec-CVS/install/linux2/blender(__gxx_personality_v0+0x1d9)[
0x491f99]
======= Memory map: ========
00400000-00aa1000 r-xp 00000000 08:01 13254729 /home/y
ellow/blender-Dec-CVS/install/linux2/blender
00ba0000-00ce1000 rw-p 006a0000 08:01 13254729 /home/y
ellow/blender-Dec-CVS/install/linux2/blender
00ce1000-04430000 rw-p 00ce1000 00:00 0 [heap]
40000000-40002000 rwxp 00000000 00:0d 1565 /dev/ze
ro
40002000-4007b000 rw-p 00000000 00:0d 1565 /dev/ze
ro
2aaaaaaab000-2aaaaab63000 rw-p 2aaaaaaab000 00:00 0
2aaaaab64000-2aaaaaba5000 rw-p 2aaaaab64000 00:00 0
2aaaaaba5000-2aaaaabd8000 r–p 00000000 08:01 11519655 /usr/li
b/locale/en_GB.utf8/LC_CTYPE
2aaaaabd8000-2aaaaabdf000 r–s 00000000 08:01 4358145 /usr/li
b/gconv/gconv-modules.cache
2aaaaabdf000-2aaaaac51000 rw-p 2aaaaabdf000 00:00 0
2aaaaac51000-2aaaaac68000 rw-s 00000000 00:08 142114816 /SYSV00
000000 (deleted)
2aaaaac68000-2aaaab668000 rw-s d0000000 00:0d 9793 /dev/nv
idia0
2aaaab668000-2aaaab669000 rw-s fc001000 00:0d 9793 /dev/nv
idia0
2aaaab669000-2aaaab6aa000 rw-p 2aaaab669000 00:00 0
2aaaab6aa000-2aaaab7ac000 rw-s 7d0bc000 00:0d 9793 /dev/nv
idia0
2aaaab7ac000-2aaaab7bc000 rw-s fc820000 00:0d 9793 /dev/nv
idia0
2aaaab7bc000-2aaaab7bd000 rw-s 7862c000 00:0d 9793 /dev/nv
idia0
2aaaab7bd000-2aaaab7be000 rw-s 4f474000 00:0d 9793 /dev/nv
idia0
2aaaab7be000-2aaaab7bf000 rw-s d71f7000 00:0d 9793 /dev/nv
idia0
2aaaab7bf000-2aaaab7cf000 rw-s d71e6000 00:0d 9793 /dev/nv idia0
2aaaab7cf000-2aaaab7d3000 rw-s 4aab4000 00:0d 9793 /dev/nv idia0
2aaaab7d3000-2aaaab8d3000 rw-s 6e559000 00:0d 9793 /dev/nv idia0
2aaaab8d3000-2aaaab8d4000 rw-s 00000000 00:08 239140867 /SYSV00 000000 (deleted)
2aaaab8d4000-2aaaab8d5000 rw-s 00000000 00:08 239173636 /SYSV00 000000 (deleted)
2aaaab8f4000-2aaaab8fe000 r-xp 00000000 08:01 11242586 /usr/li b/libXcursor.so.1.0.2
2aaaab8fe000-2aaaab9fd000 —p 0000a000 08:01 11242586 /usr/li b/libXcursor.so.1.0.2
2aaaab9fd000-2aaaab9fe000 rw-p 00009000 08:01 11242586 /usr/li b/libXcursor.so.1.0.2
2aaaab9fe000-2aaaaba07000 r-xp 00000000 08:01 11242582 /usr/li b/libXrender.so.1.3.0
2aaaaba07000-2aaaabb06000 —p 00009000 08:01 11242582 /usr/li b/libXrender.so.1.3.0
2aaaabb06000-2aaaabb07000 rw-p 00008000 08:01 11242582 /usr/li b/libXrender.so.1.3.0
2aaaabb07000

Yes, the API has changed in the upcoming version of Blender.
No, I haven’t done any work to make the script compatible with the upcoming version.
No, I still don’t know if the API will be changed to be backward compatible with the current release.

This problem has made me recognize a problem in how I was writing this script. As it is now I would have to change a couple lines in about a half dozen functions to fix this problem. Also when a UI is added how will it toggle features like this (layer grouping) across all those geometry creation functions? It would be a waste of time to simply change all the out of date code, but there isn’t time to re-write large portions of the script. For now I will try to hack together something that works with the current CVS and post it tomorrow.

Regarding 2D DXF files. It would be good imho if someone with C programming ability would take look at a few smallish typical DXF files created from say AutoCAD R12, compare them with the output created from Accutrans and look at what Accutrans does to ‘standard’ AutoCAD DXF R12 files that make the hardcoded DXF import in blender import them everytime 100% successfully, and fix the hardcoded DXF import hack thats been in blender for many years.

But any attempt to improve DXF import is of coarse welcome whether with C or Python and progress so far would suggest that its not a simple task in either case.

As for 3D import, well what’s the point? There are far better formats to import 3D data with and 3D Apps generally offer those other formats where 2D CAD Apps don’t generally.

Ok, I updated the links. This version does not work with Blender 2.42, only with CVS and later.

Yellow: I’m not sure why I should respond to you as it seems you already have an import path that works and which you like better but…
First regarding Python vs. hard coded - What difference does it make? This is one case where the ease of writing/reading Python trumps the small increase in speed possible with C. As for Accutrans/ACAD R12/every other odd dxf file - a good importer should be able to handle them all as long as they are well formed. The way the dxf format is put together leaves very few options for creating non-standard files.
Second regarding 3D import: Well, Blender is a 3D modeling/animating/rendering software. The reason I’m writing this is so I don’t need five extra steps to get solid models into Blender. Because you aren’t the only person who is ever going to use it… It’s like asking why Blender has a compositor - you may not use it, you may have the fanciest proprietary software available, but it is useful to some people and makes Blender a better tool.

I don’t know why I should have to defend myself here. I am making this thing for me and sharing it with you. If you don’t want it, don’t like it, think you could do better, go away! You are just wasting my and everyone else time spouting off about non-sense. If you have meaningful bug reports, weird dxf files, feature request, etc. thats fine, But I’m realy not interested in hearing anything else about “…forget it, quicker and easier just to open in openoffice, export as SVG and import into blender…or use accutrans to convert to a DXF that the old hardcoded DXF import handles…”.

Kitsu:

Actually I also get many errors (all +/- similar) with this new version, like this one for example:

Traceback (most recent call last):
  File "&lt;string&gt;", line 213, in main
  File "&lt;string&gt;", line 305, in drawDrawing
  File "&lt;string&gt;", line 317, in drawEntities
  File "&lt;string&gt;", line 863, in drawBlocks
  File "&lt;string&gt;", line 155, in __call__
  File "&lt;string&gt;", line 164, in add
  File "&lt;string&gt;", line 317, in drawEntities
  File "&lt;string&gt;", line 418, in drawLWpolylines
ValueError: material list must be a list of valid materials!

Sometimes it complains about other things, like having empty MTEXT entities in a dxf that hasn’t any, etc… I have seen that dxf files are a bit messy… looks like they can contain pieces of stuff that isn’t used in the drawing anymore… It seems to me that I cannot import anymore drawings that imported perfectly with earlier releases of your script… Could it be that you made it less error-tolerant?

Don’t hesitate to ask if I can help in anything, I like that script much.

Cheers

kitsu,

please ignore detractors - there are unfortunately many users who are of the opinion ‘if it isn’t useful to me - why bother’. I personally think it is great that you intend to add 3D support and feel it will be of great benefit.

LetterRIp

Hi just tried it and it appears to work.

A quick bug report - the text doesn’t go to the proper location (leo.dxf your test file…) until i select it and start a transform on it (ie I select all, the do ‘Grab, esc’ and all of the text goes to the correct location.)

LetterRip

Hi some more reports for ya

bolt1.dxf
http://www.zenstar.com/dxfobj.htm
Compiled with Python version 2.4.
Checking for installed Python… got it!
Traceback (most recent call last):
File “<string>”, line 220, in main
File “<string>”, line 309, in drawDrawing
File “<string>”, line 188, in init
File “<string>”, line 283, in getLayers
AttributeError: Object instance has no attribute ‘tables’

tree1.dxf
http://www.zenstar.com/dxfobj.htm
Compiled with Python version 2.4.
Checking for installed Python… got it!
Traceback (most recent call last):
File “<string>”, line 220, in main
File “<string>”, line 309, in drawDrawing
File “<string>”, line 191, in init
File “<string>”, line 297, in getBlocks
AttributeError: Object instance has no attribute ‘blocks’

tree2.dxf
http://www.zenstar.com/dxfobj.htm
Compiled with Python version 2.4.
Checking for installed Python… got it!
Traceback (most recent call last):
File “<string>”, line 220, in main
File “<string>”, line 309, in drawDrawing
File “<string>”, line 191, in init
File “<string>”, line 297, in getBlocks
AttributeError: Object instance has no attribute ‘blocks’

UTM001.DXF
http://aa179.cr.usgs.gov/1994_hyd/web_interface.htm
Compiled with Python version 2.4.
Checking for installed Python… got it!
Traceback (most recent call last):
File “<string>”, line 220, in main
File “<string>”, line 312, in drawDrawing
File “<string>”, line 324, in drawEntities
File “<string>”, line 872, in drawBlocks
File “<string>”, line 162, in call
File “<string>”, line 170, in add
KeyError: ‘BLK000001’

Here are where you can get the files from

sample.dxf
http://www.techsoftdesign.com/kt/eng/dxf.htm
Compiled with Python version 2.4.
Checking for installed Python… got it!
Traceback (most recent call last):
File “<string>”, line 220, in main
File “<string>”, line 309, in drawDrawing
File “<string>”, line 188, in init
File “<string>”, line 283, in getLayers
AttributeError: Object instance has no attribute ‘tables’

eldxfsample.dxf
http://www.euclidlabs.it/Components/Downloads/DXFCS/elDXFsamples.zip
Compiled with Python version 2.4.
Checking for installed Python… got it!
Traceback (most recent call last):
File “<string>”, line 220, in main
File “<string>”, line 312, in drawDrawing
File “<string>”, line 324, in drawEntities
File “<string>”, line 397, in drawLWpolylines
IndexError: list index out of range

LetterRip