Oct-22-2019, 03:51 PM
This is what I have so far. I'm not sure how robust it is
import csv import tkinter as tk from tkinter import filedialog from math import * root = tk.Tk() root.withdraw() #opened file must be NASTRAN input file. Check .nas extension file_path = filedialog.askopenfilename() nas = open(file_path ,mode = 'r', encoding = 'utf-8') n=[] x=[] y=[] z=[] nextline = 0 for line in nas: if line[:4] == "GRID": nextline = 1 n.append(line[8:8 + 16]) x.append(line[8 + 2*16:8+3*16]) y.append(line[8 + 3*16:8+4*16]) continue if nextline == 1: z.append(line[8:8+16]) nextline = 0 def scientific(coord): ind = 0 for i in coord: if i.find('+') > -1: coord[ind] = i.replace('+', 'E+') elif i.find('-') > -1: if i.find('-') == 0: s = i.lstrip('-') i = '-' + s.replace('-', 'E-') else: i = i.replace('-', 'E-') coord[ind] = i ind = ind + 1 scientific(x) scientific(y) scientific(z) with open('gridout.csv', 'w', newline='') as csvFile: writer = csv.writer(csvFile) index = 0 for i in n: writer.writerow([n[index], x[index], y[index], z[index]]) index = index + 1 nas.close()