DXF-Importer - release

It might be best just to check your importer against a dxf confromancy test suite here before looking at the above files.

http://www.crlf.de/Dateien/DXF12%20Test%20Suite.zip

here are two common errors

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’

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 289, in getLayers
UnboundLocalError: local variable ‘layers’ referenced before assignment

LetterRip

Cool! Thanks for the reports, I’ll see what I can do today :smiley:

Edit: Okay, I found part of the problem. Hidden in the DXF doc (page 173 in DXF 7.0) I found the following:

■ The entire HEADER section can be omitted if you don’t set header variables.
■ Any of the tables in the TABLES section can be omitted if you don’t need
to make entries, and the entire TABLES section can be dropped if nothing
in it is required.
■ If you define any linetypes in the LTYPE table, this table must appear before
the LAYER table.
■ If no block definitions are used in the drawing, the BLOCKS section can be
omitted.
■ If present, the BLOCKS section must appear before the ENTITIES section.
■ Within the ENTITIES section, you can reference layer names even though
you haven’t defined them in the LAYER table. Such layers are automatically
created with color 7 and the CONTINUOUS linetype.
■ The EOF item must be present at the end of file.
I was thinking I could just add a compatibility mode that only imported geometry, but it seems it is legal to drop out most of the sections of a DXF and still have a valid file. I think this will take a significant re-write to accommodate and will most likely take more time than I have in the next few days. So for now this importer is only compatible with DXF files exported from AutoCAD and perhaps other Autodesk software :frowning:

In the mean time I now have a large collection of non-standard DXF files to play with thanks to LetterRip! And yes I was too lazy to Google for my own examples :rolleyes:

Heh,

that is okay but I think perhaps it might be better to delay this till next release then. Of course if you can get it working prior to release (second week of January probably) I’ll try and slip it in still :slight_smile:

LetterRip

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.
Thanks for taking the time to respond.

First of all i recognise the importance of your script and as i’ve mentioned previously in this thread it’s very welcome, anything that makes blender better is very welcome and I’m sorry you feel you have to defend yourself.

Now my turn to defend myself, feel free not to read or respond. On reading your response to the import errors listed previously and that you stated the script was not coded for CVS version i interpreted that incorrectly, it would seem, that there would be ongoing problems with your scripts compatibility (and other scripts) with the Python API regarding back compatibility, so my thinking was as everyone who has been trying to import DXF’s for years by using work arounds, it just felt to me that the hardcoded was closer to successful imports than your script in it’s current state, if only a dev would look at the hardcoded & fix it, hence my opinion that maybe if someone looked at the hardcoded blah blah… but i understand now from what you’ve said that your script is/will be more flexible. My comment about 3D import related to the hardcoded comment not what or what not you should put in YOUR script. But other 3D formats do offer more / better features, i was unaware the very reason you were writing the script was for 3D solids import.

I was not saying that you shouldn’t bother with your script because MY workaround workflow works and your script doesn’t presently, that’s not my business. I was responding to LetterRips query as to the status of the script for inclusion with the upcoming release and as there was little other input on the thread as to whether the script worked i posted the error messages i was getting. Which leads me to my second defence:

LetterRip:

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
I posted error messages in response to your status requests, LetterRip, at a time no one else was, I took the time to, because i’d really like to see Kitsu’s script work for everyones benefit, the 3D mention as i explained related to the hardcoded, to be honest i didn’t know what purpose Kitsu was writing it for, it appears more for 3D purposes.

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.
All the files i tested were standard AutoCAD R12 files and they failed with your script, whatever accutrans does, which doesn’t appear much going on filesize changes it makes them compatible with Blenders internal DXF import.

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…”.
I hope my explanation mitigates some of what you’ve said above, i don’t think posting error messages is wasting anyones time especially when status was asked, the hardcoded import fix mention…blah blah may be nonsense to you not me, the DXF files i’m testing come straight out of AutoCAD there’s nothing ‘weird’ about them, and mentioning the workaround was for others benefit and on this thread for the purpose of history, for future visitors searching DXF import issues on BA, until your scipt works, it’s not nonsense the work around works, i also credit in earlier posts Ne0n and JMS for their valuable work and input on the SVG/Open Office work around.

There, perhaps i wasted even more of peoples valuable time, if anyone has read this through.

Although i think i’ve already thanked you Kitsu for you work i’d like to thank you again. I look forward to using your script when it works.

yellow, nice speach!
kitsu, thank you and go ahead!!!
C’mon people cooperate for what is good for all.
I am watching this thread with suspense.

Stamatis

Yeah, I’ve been a little tetchy lately. Sorry Yellow, when I re-read later I saw that you were answering LetterRip :rolleyes:

LetterRip: Good news! I’ll see if I can get it sorted.

A little deeper feedback:
Most of the errors I get with the script come from badly drawn objects in autocad (for example, a text where all content got erased. The text object is still there, but there is no text written inside). Basically, all of the drawings I didn’t drew myself give a problem when importing :slight_smile: Mines behave just a little better, this should be a good lesson for us…

By looking at the error messages, You can guess in most cases in which object type the problem was. (looking at the function name that gave the error). Another error I get often is that “material list must be a list of valid materials!” one. In that one I couldn’t figure out what was causing the problem. In 90% of the cases, though, you manage to have your drawings imported by “debugging” your drawing. (For ex: there is a problem with LWPolylines, just explode all polylines.)

By doing this way I managed to finally import all the drawings I wanted. In some I had to remove or explode most of the “complicated” entities (blocks, polylines, texts.) Unsupported entities types are simply ignored, which I find great. You normally don’t need to clean your drawings. This is probably a very idiot question, but would there be a way to simply skip drawing problematic objects?

One small bug I still have is that arcs and texts, when they manage to import, are drawn at the (0,0) location and in case of texts, at 1,000 size. Though, if you select any of them and go in edit mode, when you go out of edit mode they jump to their
correct location and size… Some update problem?

Let me know if you want me to post some problematic drawing…

Yay! I managed to grab a couple of hours this weekend and fixed most of the problems importing odd files. Turns out I didn’t do such an awful job writing this thing after all. A few minor changes and one major re-arrangement and now it imports geometry even AutoCAD refuses to load!

There are still a lot of little problems, like the text location bug and why some arcs are messed up, but this release should work a lot better than the last. I also added first draft support for true polyline objects. Currently odd things like polyface meshes/splines/fitted curves/etc. are ignored, though splines/curves are usable now with a bit of editing.

I added support for the new visability/rendering toggles in CVS, but I had to remove it because there is no good way to control it in Blender. If there were some way to select a group and toggle those settings it would work a lot better for simulating layers…
I guess I need to bug the developers a little - see if I can get some of these bugs/incomplete features cleaned up before the release :smiley:

So test it out and let me know what’s still broken. Remember this version is for CVS and later only. Also remember to clean out/update your .blender/scripts and bpymodules directories if you have installed a previous version - that was the cause of a great deal of the errors on my end for several days :rolleyes:

hi where is the updated link to the new version? is it the first link?

LetterRip

Updated again: fixed some bugs in drawing arcs and some text placement issues.

LetterRip: Yeah, first post. At first I was just updating the zip file on my server, but now that I’ve started pre-pending the version to the zip file I have to edit the link every time… Would you prefer I post a new link per version?

Hi Kitsu

I’ve been testing your latest script release .08 at work on windows with two recent CVS builds from www.graphicall.org the one is the image refactor build, the other is a particle patched build (not that it has any bearing on the script), however the two give different results. The sample DXF files you include in the release work on both builds. However i have failed yet to import any substantial R12 or R2000 DXF from AutoCAD. A very simple drawing such as a few lines and arcs (a simple 2D arched window in elevation) imports fine but a more substantial drawing (1mb+) in this case 2D building elevations fail with both builds.

The latest particle build throws up a warning message which I’m sure you are aware of:

After 2.43 .append()WARNING: grp.objects.append() has been depreciated use grp.objects.link() instead.

It’s only a warning but the import fails blender just stops responding part way through the import (I’ve tried reducing the content of the drawing to see if i can establish what stops it but no luck)

On the particle build the console screen is constantly scrolling the above error message and then stops and on the image refactor build there’s no error messages but blender just stops responding after a minute or two.

I’m going to give it ago now at home on linux with a CVS build from tonight and a selection of DXF’s from previous projects to see if i have better luck.

What is very encouraging is seeing your sample DXF’s import cleanly. Looking good.:slight_smile:

Actually I think the problem is patience rather than software :wink:

In my tests with large files (bolt1,tree1, and tree2 posted by letterrip) I noticed that at some random point during import Blender turns off the ‘wait cursor’ and shows a script window. If you leave it alone it eventually loads the file, or you can flip over to the console and hit ctrl-c to kill the script mid-import.

Funny that you posted this. Just today I added psyco support and a note in the docs about just this problem. Once major development has settled down I plan to go back and do some optimization. Unfortunately it would probably be wasted effort at this point.

Hi kitsu on your test files i get

big-test (and others )

Blender releases after 2.43 will not support .append()WARNING: grp.objects.appen
d() has been deprecated, use grp.objects.link() instead.

Traceback (most recent call last):
File “<string>”, line 358, in main
File “<string>”, line 443, in drawDrawing
File “<string>”, line 455, in drawEntities
File “<string>”, line 285, in call
File “<string>”, line 606, in drawText
AttributeError: Text instance has no attribute ‘halignment’

LetterRip

Actually I think the problem is patience rather than software :wink:

Well I’ve found it to be a bit of both, patience and software.

Any importer takes time and i have patience, i don’t expect instant results. :slight_smile: The files i tried last night at home all failed except one, a 1.7mb file of simple lines, on one layer. Yes i had noticed the ‘wait cursor’ switching off and a minute or two later either an outright crash wiping the blender session off my desktop (linux) or freezing solid on windows, or just the once a successful import, which was good to see.

Not of much importance but a visual feedback status bar or similar would be good at some point.

So far i’m not having any success importing 2D AutoCAD DXF files, haven’t tried 3D. I am ensuring they are as simple as possible, well constructed and that an erase all, remove from selection and purge is done to remove the hidden entities Yorik mentions, although i’ve always done that in my day to day AutoCAD work.

I’ll keep trying.

LetterRip: That is pretty strange. I know when I added that bug, and I know that I fixed minutes afterward. I’ve successfully imported nearly all the test files you provided except the dimension tests. I put a fresh update up on my site - Try first deleting any trace of older versions of the script from you .blend and working scripts folder, then try the current version.

Yellow: Did you try ctrl-c at the command-line/console? You can try the updated version too, it has psyco enabled and it loaded a file that took ~5min to load yesterday in less than one this morning. Also could you post/pm/email me some samples of the files that aren’t working for you? Like I said 95% or more of my test cases are passing now.

Darn, I was ready to start working on sat import too. Yesterday afternoon I finally figured out how to decrypt sat data stored in dxf files (stupidest encryption ever too… very embarrassing) and I re-read the format spec again (worst file format spec ever btw). Hopefully with this post I got you guys straightened out and this version is ready for inclusion… but let me know if anything really needs fixing. I would like to have all these bugs worked out before every Blender user in the world gets a chance to poke at it :wink:

Edit: Okay, I downloaded RC1 to test it out and that depreciation warning is really annoying! It slows the script down by at least 10 fold… Which is silly because it is in a try/except block with the new syntax just below… I’ll post another update in just a while.

kitsu,

I have to say that I’m very excited that you’re taking an interest in this. I often struggle with getting Blender to import 3D CAD files for visualization and whatnot. I’ve done CAD importing and exporting for 17 years, and I, by far, struggle with DXF/DWG the most.

Anyway, what you’re doing is excellent… and is appreciated.

Iso

Yellow: Did you try ctrl-c at the command-line/console? You can try the updated version too, it has psyco enabled and it loaded a file that took ~5min to load yesterday in less than one this morning. Also could you post/pm/email me some samples of the files that aren’t working for you? Like I said 95% or more of my test cases are passing now.
I tested on windows today with the official RC1, i spent all day on and off at work testing with as many different projects i could, exporting as R12 DXF, first ensuring that the files were as simplified as practically possible, however they weren’t very simple stuff, i’m testing on the source files i would use with Accutrans / Open Office workflow. 2D buidling plans and elevation drawings.

Not one completed successfully with RC1. ctrl c with RC1 left a unresponsive blender session. Sure i got the keyboard interrupt in the console but blender was unusable after, just a black screen and i waited for that in case blender needed time to catch up. However i’m testing on a Core2Duo E6700, 2GB 900mhz RAM and a Nvidia 7650 GTX Vid card, so i don’t know how long i should have to wait.

However on an earlier build, the image refactor one, i could ctrl c and get back into blender, then i had partial import success, which was encouraging.

But with RC1 ctrl c didn’t allow me back into blender.

So the script is impractical to use for me, i don’t know how others are fairing, as there seems little other input on this thread, are others testing?.

Accutrans / Open Office workflow is 100% successful with even the most unclean DXF exports from AutoCAD.

I’ll sort out some test files for you to look at, you’re in a better position than me to locate the source of the problem. thanks.

same error here as last time - using the .8 downloaded version, and with clearing out all old versions… file>import>Drawing eXchange Format (.dxf)

LetterRip

note that running the script i n your blend, instead of from the file menu gives

Traceback (most recent call last):
File “C:\cygwin\home\TomM\bf\blender\obj\2.42a\blender-2.42a-windows.blender
scripts\import_dxf.py”, line 370, in main
drawDrawing(drawing)
File “C:\cygwin\home\TomM\bf\blender\obj\2.42a\blender-2.42a-windows.blender
scripts\import_dxf.py”, line 455, in drawDrawing
drawEntities(drawing.entities, settings)
File “C:\cygwin\home\TomM\bf\blender\obj\2.42a\blender-2.42a-windows.blender
scripts\import_dxf.py”, line 467, in drawEntities
drawer(entities.get_type(_type), settings, group)
File “C:\cygwin\home\TomM\bf\blender\obj\2.42a\blender-2.42a-windows.blender
scripts\import_dxf.py”, line 297, in call
ob = self.draw(entity, settings.curves)
File “C:\cygwin\home\TomM\bf\blender\obj\2.42a\blender-2.42a-windows.blender
scripts\import_dxf.py”, line 618, in drawText
if text.halignment == 0:
AttributeError: Text instance has no attribute ‘halignment’

LetterRIp

Kitsu:

Don’t know whether i should post this on the thread, it’s DXF import related but not related to your script.

I’ve noticed a fundamental difference between how version 2.37a handles imports from DXF’s and any version after. To illustrate:

http://yellowsblog.wordpress.com/files/2007/01/post-237a.png

http://yellowsblog.wordpress.com/files/2007/01/237a.png

Which one would be considered the correct way? This is why i still have to use 2.37a to model from DXF’s. If i create faces from the DXF vertices/edges and then extrude the faces i get the above in the two different versions, however if i use any version after 2.37a and extrude first then create the faces i don’t get the nasty meshes. Odd that. Is it a problem with normals? Could your script eventually fix the problem? Has anyone noticed also that if you extrude a face that shares vertices or edges that the face extrusion is hollow underneath / backside. If the face is separate from anything else then it extrudes correctly and has a solid back. That happens with all versions though.

Sorry, just thought this was a good thread to add this problem to, maybe someone looking could explain / solve it.