Search code examples
pythonparsingdxf

dxf file parsing with dxfgrabber library in the python


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.


Solution

  • 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.