read_text_lines_from_dxf.py 903 B

123456789101112131415161718192021222324252627282930313233
  1. import csv
  2. import math
  3. def printsection(buffer, file_out):
  4. obj = dict(zip(buffer[::2], buffer[1::2]))
  5. for keys, values in obj.items():
  6. if keys == '1':
  7. try:
  8. row = [values, math.floor(float(obj['10'])),math.floor(float(obj['20']))]
  9. with open(file_out, 'a') as csvFile:
  10. writer = csv.writer(csvFile, delimiter =';')
  11. if row[0] != '':
  12. writer.writerow(row)
  13. csvFile.close()
  14. except:
  15. print("ERROR")
  16. def read(file, file_out):
  17. buffer = []
  18. file = open(file, "r")
  19. for line in file:
  20. line = line.strip()
  21. #print(line)
  22. if line == '100':
  23. printsection(buffer, file_out)
  24. buffer = []
  25. buffer.append(line)
  26. printsection(buffer, file_out)
  27. read("../drawings/sample.DXF", "sample.csv")