[PythonCAD] First hack at DWG reading

Art Haas ahaas at airmail.net
Wed Aug 27 19:26:35 EDT 2003


Hi.

I've finished up the first shot at reading DWG files. I downloaded the spec
from the OpenDWG group and have coded up a beastly little thing that does
nothing other than print out what it finds in the DWG file it is reading.

The script will only work on R13/R14 version files as those versions are
what the spec describes. I've run this thing on the sample files that
people have mailed me (thanks!), and the script doesn't bomb out when
looking at the data in the file. That's good, but this thing need much
more testing as the files I have contain a limited number of entity
types. It would be great of some people with lots of R13/R14 files could
try and run the script on the files and see if it reads them without
an error.

So, where is this script you ask? I thought about mailing it with this
posting, but it is 20K gzipped and there is no need to clutter up your
mailbox with 20K of stuff if you can't test it. If only the wankers who
write e-mail worms or generate spam mail would be so kind. If you can
test this and would like to do so, write me and I'll mail it to you.

The script will run like this ...

$ python dwg.py /path/to/the/dwg/file/you/will/test.dwg

If it is an R13/R14 file the script will print out _lots_ of stuff as it
reads the data in the file. Hopefully there will not be any error
messages. Earlier or later versions of the format will generate an
'unknown format' message. The script only reads the files and prints
stuff out - it does _not_ modify the DWG file. I expect to have to make
several iterations on this script before it reads the files people
test it on work decently.

The script reads nearly all the entities described in the OpenDWG spec,
and nearly completely. There are a number of entities that not all the
data is read and processed, and some entitles like 'OLE2FRAME' entities
are not read at all. The entities that PythonCAD can deal with - lines,
circles, points, etc. - all seem to be read well enough that the
ability to import the data from DWG into PythonCAD looks like a very
achievable goal. There is still much I don't understand about the DWG
file format (and many other things) so documentation, references, and
help in deciphering the format will be greatly appreciated.

I've also sent some stuff up to the repo - the line clipping stuff I
worked on a week or two ago, and I've added a change the the text.py
file that should fix the Python-2.3 problem.

Let me know if you want to have the dwg.py file and I'll send it along.

Art
-- 
Man once surrendering his reason, has no remaining guard against absurdities
the most monstrous, and like a ship without rudder, is the sport of every wind.

-Thomas Jefferson to James Smith, 1822



More information about the PythonCAD mailing list