Using ACT, how can I create a result for each time step and export result to a text file?
Using ACT, how can I create a result for each time step and export result to a text file?
Best Answer
-
One can adapt the following code:
Store link to solution
solu=ExtAPI.DataModel.Project.Model.Analyses[0].Solution
Obtain list of time sets
ResData=ExtAPI.DataModel.Project.Model.Analyses[0].GetResultsData() DataSets=ResData.ListTimeFreq
Loop through data sets
for DataSet in range(len(DataSets)):
Define display time
DisplayTime=DataSets[DataSet] UnitTime='[sec]'
Insert result and evaluate
result=solu.AddMaximumPrincipalStress() result.DisplayTime=Quantity(str(DisplayTime) + UnitTime) solu.EvaluateAllResults()
Export result to text file
FilePath=r"D:\Test\Export" FileExtension=r".txt" result.ExportToTextFile(True,FilePath+str(DisplayTime)+FileExtension)
2
Answers
-
Hello Pernelle,
thank you for that very useful code. I use it in Mechanical to get the Equivalent Stress results for each time step. But as I have 30 substeps the solution tree is getting quite crowded. Hence my question: is it possible to write the results only into text files without displaying them in Mechanical as Solutions?0 -
Hi @Niklas_01, there are a couple of options here:
- Insert only result in the Mechanical tree and change its display time and export for all time steps. This will however take much longer to execute than the above method.
- Keep the above method and delete all the result objects after you have exported all the info.
- Directly read the result file through GetResultsData
- Use DPF to do the postprocessing.
An example of methods #2 and #3 is given here: https://discuss.ansys.com/discussion/660/how-to-iterate-through-load-steps-for-result-objects
For method #4, see this post on how to get started: https://discuss.ansys.com/discussion/3074/getting-started-with-dpf-in-mechanical1