[PythonCAD] Improved DWG reader, take 2 ...

Art Haas ahaas at airmail.net
Sun Oct 5 17:01:51 EDT 2003


I've hacked and beaten the R13/R14 reader into something that now fits
in with my design for the general DWG file reader, and it is available
for testing. If you want to try it out, send me an e-mail and I'll mail
the files to you. You'll get a tar archive with 'dwgbase.py',
'dwg1314.py', and 'dwg15.py'. Using these files is pretty much like I'd
described in my earlier mail regarding my design for the
revision-neutral DWG reader.

Here's the link to my initial mail posting and an early description
of how things work.


I've made a few changes since then - the '_setXXX' methods lose the
leading underscore (I'm funny about underscores), but these methods are
still only meant for use within the actual file reading and data
extraction code. The 'getXXX' methods are meant for use to retrieve the
values from the Dwg instance and the various dwgEntity instances. I've
also changed a few dictionary keys here and there to strings I thought
were a little clearer.

Here's a simple example that gets all the objects out a a file:

$ python
>>> import dwgbase
>>> dwg = dwgbase.Dwg("/path/to/the/file.dwg")
[ ... the 'file.dwg' can be an R13, R14, or R15 file ... ]
>>> objs = dwg.getObjects()
[ ... the 'objs' will be a list of dwgEntity objects - we'll look at
      the first one ... ]
>>> obj = objs[0]
>>> obj.getType()
>>> obj.getEntityKeys()
['foo', 'bar', 'blah']
>>> fooval = obj.getEntityData('foo')
>>> barval = obj.getEntityData('bar')

I've added lots of doc strings to the 'dwgbase.py' file to provide a
starting point of documentation. Getting the object data for each of the
objects in the DWG file is pretty much done like in my fictional example
above - the getEntityKeys() returns descriptive strings listing the
data that is unique for the object, and getEntityData() returns the
value for that key.

I've tried my new-fangled reader on a number of different DWG files, and
it has worked decently enough. So now it goes out in hopes of generating
some feedback. Thanks in advance to anyone wishing to test this.

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