3

I want to parse dxf file for obtain objects (line, point, text and so on) with dxfgrabber library.

The code is as below

#!/usr/bin/env python
import dxfgrabber

dxf = dxfgrabber.readfile("1.dxf")
print ("DXF version : {}".format(dxf.dxfversion))

But it gets some error...

Traceback (most recent call last):
  File "parsing.py", line 6, in <module>
    dxf = dxfgrabber.readfile("1.dxf")
  File "/usr/local/lib/python2.7/dist-packages/dxfgrabber/__init__.py", line 43, in readfile
    with io.open(filename, encoding=get_encoding()) as fp:
  File "/usr/local/lib/python2.7/dist-packages/dxfgrabber/__init__.py", line 39, in get_encoding
    info = dxfinfo(fp)
  File "/usr/local/lib/python2.7/dist-packages/dxfgrabber/tags.py", line 96, in dxfinfo
    tag = next(tagreader)
  File "/usr/local/lib/python2.7/dist-packages/dxfgrabber/tags.py", line 52, in __next__
    return next_tag()
  File "/usr/local/lib/python2.7/dist-packages/dxfgrabber/tags.py", line 45, in next_tag
    raise StopIteration()
StopIteration

The simple 1.dxf file only contain line.

file link is https://docs.google.com/file/d/0BySHG7k180kETlQ2UnRxQmxoUk0/edit?usp=sharing

Is this bug of dxfgrabber library? Is there any good library for parsing dxf file in the python?

I am using dxfgrabber 0.4 and python 2.7.3.

Danil Chernokalov
  • 755
  • 1
  • 10
  • 31

2 Answers2

4

I contacted the developer and he says that in current version 0.5.1 make line 49 of __init__.py the following: with io.open(filename) as fp:. Then it works (io was missing). He will make this correction official in version 0.5.2 soon.

solarisman
  • 256
  • 1
  • 4
  • 16
  • This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](http://stackoverflow.com/questions/ask). You can also [add a bounty](http://stackoverflow.com/privileges/set-bounties) to draw more attention to this question once you have enough [reputation](http://stackoverflow.com/faq#reputation). – Baby Groot May 15 '13 at 06:51
0

You can only read dxf made in AutoCAD format! Try "DraftSight" which is a free AutoCAD clone which exports dxf quite well. Try dxf R12 format. This will solve your problems.

Name
  • 1