-
-
April 25, 2024 at 10:42 amChan-Hua YehSubscriber
I have a static structural analysis in Workbench, and I would like Ansys Mechanical to automatically export the tabular data after solving a design point. Does anybody know how to do this?
Problem description:
Currently, for every design point, I have to right click "set as current", and wait for opening Mechanical, export the data manually, wait for closing Mechanical, which is quite time-consuming and laborious. It usually takes 1 munites to open or close the Mechanical. Here is how I manually export the .xls file now:
Attempts:
I have tried to put some Python code in "Python Code" under solution, and successfully export a blank csv file after solution. However, I couldn't find an API to retrieve the result data to put in my csv and I don't know if this way is the right way.
I am using Workbench 2022 R1 Enterprise.
Thank you in advance!
-
April 25, 2024 at 11:38 amAvnish PandeyAnsys Employee
Hi Chan,
To automatically export the tabular data after solving a design point in Ansys Mechanical, you can utilize an Ansys ACT extension. This extension can automate the export of various data during the update process for a Component/System/Project and Design Point. It streamlines the process, especially when dealing with a large number of design points.
Additionally, you can group many result items into the same table and export them. This option becomes available when you first right-click on "Solution" and choose "Results Summary." Then, right-click on "Solution" again and select "Export"
-Best
-
April 25, 2024 at 1:30 pm
-
April 27, 2024 at 10:37 amChan-Hua YehSubscriber
Thank you, Mr. Pandey, but I am not allowed to install additional extensions at the moment.
Thank you, Mr. Kostson. Your information did help! Now I can export a text file after solving using “result.ExportToTextFile(export_name+’.txt’)” in the postprocessing section:
Q1:
However, the exported txt files for each design point (dp) are the same.For example, if I have 3 design points, it can output 3 txt files after solving (the txt file names are different by adding system time), but all 3 txt files contain the same data, which belongs to the current design point. That is, no matter how many design points it solves, Ansys Mechanical only exports one design point’s data.
Q2:
May I ask if the design point parameters can be retrieved in the “Python Code” object?
Since there are many design points, it would be nice if Mechanical could export results with parameters in the file names. For example:
”force_1N_pressure_1Pa_stress.txt” or “force_5N_length_1m_directional deformation.txt”
I have searched and got this information, which says we can access model settings using Python APIs:
So I have tried many attributes, but couldn’t find anyone that worked. The closest attribute I’ve found is “GetParameter”, but it still didn’t help.
Thank you very much for any help!
-
-
April 29, 2024 at 6:44 amErik KostsonAnsys Employee
Hi
I have added a comment in my post :
Just search and look up wbjn and dpn (design point number).
Erik
-
April 30, 2024 at 11:02 pmChan-Hua YehSubscriber
Thank you a lot for editing your post! Now I can add the “dpn” in the file names!
There is only one thing: the content of each txt file is yet still the same as the current design point, not from each design point’s data.
For example, there are four design points, and after one of them is updated, a txt file would be generated. There are four txt files with “dpn” in their file names in the end, but the data in each file is exactly the same as the current one (DP 1).
If I change the current design point to DP2, all four txt files would contain the same data as DP2.
Here is my code. I have added “Tree.Activate(result)” as you suggested in your post, hoping that Ansys refreshes results before exporting txt files, but it seems it’s not working. Do you know how to deal with this issue? And may I ask if “Python Code” is the correct place to put my code for automation?
import csv, os
import tempfile
import mech_dpf, wbjn
import Ans.DataProcessing as dpffres = []
fres.Add('Ansys.ACT.Automation.Mechanical.Results.DeformationResults.DirectionalDeformation')
analysis = ExtAPI.DataModel.Project.Model.Analyses[0]
solution = analysis.Solution
all_results = solution.Children
dpn = wbjn.ExecuteCommand(ExtAPI,"returnValue(a+Parameters.GetActiveDesignPoint().Name)",a="DP")
target_folder = r'test'
for result in all_results:
restype = str(result.GetType())
if restype==fres[0] and result.Name == "Directional Deformation 2":
Tree.Activate(result)
export_name = os.path.join(target_folder, result.Name)
export_name = export_name + "-" + str(dpn) + "-" + str(round(os.times()[1],3))
result.ExportToTextFile(export_name+'.txt') -
May 1, 2024 at 6:38 amErik KostsonAnsys Employee
Hi
See the post below (see all steps, e.g, after post callback, and especially the last part in that post).
https://developer.ansys.com/blog/script-tip-friday-python-code-object-mechanical
All the best
Erik
-
May 1, 2024 at 9:16 amChan-Hua YehSubscriber
It works! Thank you very much!
My fault. I didn't notice that "callback" is a terminology.
Your help will save me a lot of time!
Summary:
1. What's the goal?
Exporting raw data after solving each design point
2. Where is the information about this?
Export to file, callback after post
3. Where to put the code for automation?
"Python Code" under "Solution", not anywhere else (ex. not "Mechanical Scripting" nor "Python Result")
In Mechanical, right-click on "Solution"->insert->"Python Code"
In Details of "Python Code", select "After Post" in "Target Callback"->right-click on "Python Code"->connect
Now the environment is ready.
4. What is the code?
def after_post(this, solution):# Do not edit this line
"""
Called after post processing.
Keyword Arguments :
this -- the datamodel object instance of the python code object you are currently editing in the tree
solution -- Solution
"""
# To access properties created using the Property Provider, please use the following command.
# this.GetCustomPropertyByPath("your_property_group_name/your_property_name")
# To access scoping properties use the following to access geometry scoping and named selection respectively:
# this.GetCustomPropertyByPath("your_property_group_name/your_property_name/Geometry Selection")
# this.GetCustomPropertyByPath("your_property_group_name/your_property_name/Named Selection")
import csv, os
import tempfile
import mech_dpf, wbjn
import Ans.DataProcessing as dpf
fres = []
fres.Add('Ansys.ACT.Automation.Mechanical.Results.DeformationResults.DirectionalDeformation')
analysis = ExtAPI.DataModel.Project.Model.Analyses[0]
solution = analysis.Solution
all_results = solution.Children
dpn = wbjn.ExecuteCommand(ExtAPI,"returnValue(a+Parameters.GetActiveDesignPoint().Name)",a="DP")
# write results to txt file
target_folder = r'test'
for result in all_results:
restype = str(result.GetType())
if restype==fres[0] and result.Name == "Directional Deformation 2":
Tree.Activate(result)
export_name = os.path.join(target_folder, result.Name)
export_name = export_name + "-" + str(dpn) + "-" + str(round(os.times()[1],3)) #include dp number and time in the file names
print(export_name)
result.ExportToTextFile(export_name+'.txt')
pass -
May 1, 2024 at 9:29 amErik KostsonAnsys Employee
That is great - many thanks for your post - as this might be useful to others we are closing it.
All the best
Erik
-
- The topic ‘How to automatically export .csv or .xls after solving each design point?’ is closed to new replies.
- Problem with access to session files
- Ayuda con Error: “Unable to access the source: EngineeringData”
- At least one body has been found to have only 1 element in at least 2 directions
- Using APDL to extract stresses on a beam element.
- Error when opening saved Workbench project
- How to select the interface delamination surface of a laminate?
- Geometric stiffness matrix for solid elements
- Timestep range set for animation export
- SMART crack under fatigue conditions, different crack sizes can’t growth
- Coupled Transient Thermal Analysis with LS-Dyna Structural Simulation
-
1181
-
488
-
487
-
225
-
201
© 2024 Copyright ANSYS, Inc. All rights reserved.