Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update FLEX.py #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 67 additions & 42 deletions FLEX.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,33 @@
import os
from tkinter import filedialog
from tkinter import *
from tkinter import Tk, Frame, BOTH, LEFT
from tkinter import messagebox
from tkinter.ttk import Combobox



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
"""
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 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
with open(inputFile, 'r') as g:
loadcases = [re.split(" ",lines,7)[6]
for lines in g if lines.startswith(Results_Type)]
nameLoadcases = [Results_Type] + loadcases

return (values, len(data), nameLoadcases)
return (values, len(data), nameLoadcases)

"""
Main Program execution function
Expand All @@ -35,23 +38,25 @@ def parse_data_file(inputFile):

def run_extraction():

""" Create output Excel file"""
""" Create output Excel file"""

wb = xlwt.Workbook()

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].strip('"'))
else:
ws.write(i, j, date[i][j - 1])
wb.save('Results.xls')

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')
messagebox.showinfo('Status', 'Execution Successful')


"""
Expand All @@ -60,19 +65,25 @@ def run_extraction():


def browse_data_file():
global lst
filez = filedialog.askopenfilenames(
initialdir="/", title="Select file", filetypes=((
"dat files", "*.dat"), ("all files", "*.*")))
lst = list(filez)
return (lst)
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")
master.wm_title("FLEX - Freebody Extractor")
lst = []

def onChangeValue(object):
global Results_Type
Results_Type=str('"'+combobox.get()+'"')

"""
Create buttons and text for GUI
Expand All @@ -83,18 +94,32 @@ def main():
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"
"Step.2. Choose type of the results from the dropdown box\n"
"Step.3. Run the program\n"
"Step.4. 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")
frame = Frame(master)
frame.pack(fill=BOTH)
combobox=Combobox(master)
items=("Freebody Loads","Applied Loads", "Constraint Forces", "Internal Forces", "Summation of Forces")
combobox["values"]=items
combobox.current(3)
global Results_Type
Results_Type ='"Internal Forces"'
combobox.pack(side=LEFT)
combobox.bind("<<ComboboxSelected>>", onChangeValue)

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()