read_text_lines_from_dxf.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import csv
  2. import math
  3. def printsection(buffer, file_out):
  4. #print(b)
  5. obj = dict(zip(buffer[::2], buffer[1::2]))
  6. for keys, values in obj.items():
  7. if keys == '1':
  8. try:
  9. #print(values)
  10. #print('{},{}'.format(obj['10'], obj['20']))
  11. #print("\n")
  12. row = [values,math.floor(float(obj['10'])),math.floor(float(obj['20']))]
  13. with open(file_out, 'a') as csvFile:
  14. writer = csv.writer(csvFile, delimiter =';')
  15. if row[0] != '':
  16. writer.writerow(row)
  17. csvFile.close()
  18. except:
  19. print("ERROR")
  20. #print(b)
  21. #if obj.get('1'):
  22. # print('{}'.format(obj['1']))
  23. def read(file, file_out):
  24. buffer = []
  25. file = open(file, "r")
  26. for line in file:
  27. line = line.strip()
  28. #print(line)
  29. if line == '100': # we've started a new section, so
  30. printsection(buffer, file_out) # handle the captured section
  31. buffer = [] # and start a new one
  32. buffer.append(line)
  33. printsection(buffer, file_out)