dxf_line_reader.py 752 B

123456789101112131415161718192021222324252627
  1. def printpoint(b):
  2. print(b)
  3. obj = dict(zip(b[::2], b[1::2]))
  4. if obj['100'] == 'AcDbMText':
  5. print('{}'.format(obj['0']))
  6. buffer = ['0', 'fake']
  7. filepath = 'GV_12.DXF'
  8. with open(filepath,'r', errors="replace") as fp:
  9. line = fp.readline()
  10. cnt = 1
  11. while line:
  12. line = fp.readline()
  13. line = line.rstrip()
  14. if line == '0': # we've started a new section, so
  15. print("Line {}: {}".format(cnt, line.strip()))
  16. printpoint(buffer) # handle the captured section
  17. buffer = [] # and start a new one
  18. buffer.append(line)
  19. cnt += 1
  20. printpoint(buffer) # buffer left over from last pass through loop
  21. #https://leancrew.com/all-this/2016/12/dxf-data-extraction/