-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathFLEX.py
100 lines (77 loc) · 2.71 KB
/
FLEX.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import re
import xlwt
import os
from tkinter import filedialog
from tkinter import *
from tkinter import messagebox
def parse_data_file(inputFile):
"""
Data is the list that contains all the forces/moments data in string format.
Open the dat file, go through every line, stop at line Totals, take line and
split at comma, take last 6 values from the line and convert them to float.
Similar to numerical value extraction, we extract the loadcases name from
the input file.
"""
with open(inputFile, 'r') as f:
data = [list(map(float, line.split(',')[4:]))
for line in f if line.startswith('Totals')]
values = [["Fx", "Fy", "Fz", "Mx", "My", "Mz"]] + data
with open(inputFile, 'r') as g:
loadcases = [re.split(" ",lines,18)[6][:-1]
for lines in g if lines.startswith('"Freebody Loads"')]
nameLoadcases = ["Freebody Loads"] + loadcases
return (values, len(data), nameLoadcases)
"""
Main Program execution function
"""
def run_extraction():
""" Create output Excel file"""
wb = xlwt.Workbook()
global lst
for filename in lst:
date, lenCases, loadcases = parse_data_file(filename)
head, tail = os.path.split(filename)
ws = wb.add_sheet(tail)
for i in range(lenCases + 1):
for j in range(7):
if j == 0:
ws.write(i, j, loadcases[i])
else:
ws.write(i, j, date[i][j - 1])
wb.save('Results.xls')
messagebox.showinfo('Status', 'Execution Successful')
"""
TKINTER Module for GUI implementation
"""
def browse_data_file():
global lst
filez = filedialog.askopenfilenames(
initialdir="/", title="Select file", filetypes=((
"dat files", "*.dat"), ("all files", "*.*")))
lst = list(filez)
return (lst)
def main():
master = Tk()
master.wm_title("FLEX - Freebody Loads Extractor")
lst = []
"""
Create buttons and text for GUI
"""
T = Text(master, height=10, width=60)
T.pack()
T.insert(END, "This is a script for extracting forces and moments "
"from the\nFreebody Load .dat file generated by Patran.\n\n"
"Step.1. Browse for the .dat files and select all of them\n"
"Step.2. Run the program\n"
"Step.3. A Results.xls file will be created with the totals\n"
"output for each Load Case in a separate worksheet\n\n"
"Note: Name of the .dat file should not exceed 27 characters")
b = Button(master, text="Browse file", bg='red',
width=10, height=2, bd=3, command=browse_data_file)
b.pack(side=LEFT)
c = Button(master, text="Run", bg='green',
width=10, height=2, bd=3, command=run_extraction)
c.pack(side=LEFT)
master.mainloop()
if __name__ == "__main__":
main()