How do I export average values of all results in a folder to a CSV file in Mechanical?
Ayush Kumar
Member, Moderator, Employee Posts: 442
✭✭✭✭
How do I export average values of all results in a folder to a CSV file in Mechanical?
Tagged:
0
Comments
-
The following code can be as is in the Mechanical Scripting console to get a csv file written out in the Solver Files Directory. Make sure that all the results you want exported are grouped together in a Folder called "Export"
import os export_folder = ExtAPI.DataModel.GetObjectsByName("Export")[0] all_res = export_folder.Children analysis = Model.Analyses[0] unit = analysis.CurrentConsistentUnitFromQuantityName("%s" % all_res[0].OutputUnit) out_dir = analysis.WorkingDir out_file_path = os.path.join(out_dir, "all_avg_res.csv") out_file_handle = open(out_file_path, "w") out_file_handle.write("Result Name;Value in [%s]\n" % unit) for res in all_res: out_file_handle.write("{0}; {1}\n".format(res.Name, res.Average.Value)) out_file_handle.close()
0