September 5, 2023 at 10:00 amAkshay PanchwaghSubscriber
I am trying to automate my transient thermal simulations by including Python scripts to automatically save the results in a CSV file while updating the Design Points through Workbench without having to open Mechanical. After much efforts, I was able to come up with a code which (possibly) saves results without accessing the Tabular Data in Mechanical. But a new problem has arisen. When I execute the below mentioned script in Mechanical Scripting/Shell, it works perfectly. But when I use it as a Python Code object and trigger it after Post, my Workbench and Mechanical crash catastrophically.
Can anyone please help me to figure out what is going wrong? Here is the script:
userfilesdir = wbjn.ExecuteCommand(ExtAPI,"""returnValue(GetUserFilesDirectory())""")
file_name = os.path.join(userfilesdir, str(int(70))+"data.csv")
file_handle = open(file_name, "wb")
time_unit = ExtAPI.DataModel.CurrentUnitFromQuantityName("Time")
temp_unit = ExtAPI.DataModel.CurrentUnitFromQuantityName("Temperature")
ResultsOfInterest = 
reader = Model.Analyses.GetResultsData()
rsets = reader.ResultSetCount
for index, temp in enumerate(solution.Children):
if temp.GetType() == Ansys.ACT.Automation.Mechanical.Results.ThermalResults.TemperatureResult:
if temp.Name in ResultsOfInterest:
#n += 1
temp.By = Ansys.Mechanical.DataModel.Enums.SetDriverStyle.ResultSet
for rset in range(1,rsets+1):
temp.SetNumber = rset
result_avg = temp.Average
result_max = temp.Maximum
result_min = temp.Minimum
result_tstep = rset
file_handle.write("%s;" % result_tstep)
file_handle.write("%s;" % result_min)
file_handle.write("%s;" % result_max)
file_handle.write("%s;" % result_avg)
Thank you in advance.
September 6, 2023 at 9:39 amSaumadeepAnsys Employee
The first I would do in this case is to make sure that there is no issue with my system and installed software. For that, I would do the following:
- Make sure that you meet the system requirements. Check this in the section "System and Browser requirement" on this site - Download Ansys Student | Workbench-based Simulation Tools
- Do an app data reset. You can follow the steps shown here in this Ansys forum thread - Crashing of mechanical ANSYS
If after following these steps, you face the same issue then let us know about it here.
September 6, 2023 at 11:38 amAkshay PanchwaghSubscriber
I tried to implement this. The problem with Workbenh crashing occurs intermittently. It is not happening regularly. But I do get a script error when I try to run the above mentioned script as a Python Code object. As I mentioned there, the script runs fine in the Mechanical Scripting tab. But when I use it as a Python Code object, I get a script error. Can anyone please help me understand why this is happening?
What the code does is that it loops through every solution object mentioned in the list "ResultsOfInterest" for the number of timesteps I have. It collects the result values and writes them to the CSV file. But this happens only when the code is executed in Mechanical Scripting. If I try to execute this script in a Python Code object, the code somehow remains stuck on the first time step of the 1st solution in the list. It does not move beyond that.
Below is the script error I receive.
Can anyone please help me with this?
- You must be logged in to reply to this topic.
Boost Ansys Fluent Simulations with AWS
Computational Fluid Dynamics (CFD) helps engineers design products in which the flow of fluid components is a significant challenge. These different use cases often require large complex models to solve on a traditional workstation. Click here to join this event to learn how to leverage Ansys Fluids on the cloud, thanks to Ansys Gateway powered by AWS.
Earth Rescue – An Ansys Online Series
The climate crisis is here. But so is the human ingenuity to fight it. Earth Rescue reveals what visionary companies are doing today to engineer radical new ideas in the fight against climate change. Click here to watch the first episode.
Subscribe to the Ansys Blog to get great new content about the power of simulation delivered right to your email on a weekly basis. With content from Ansys experts, partners and customers you will learn about product development advances, thought leadership and trends and tips to better use Ansys tools. Sign up here.
- Solver Pivot Warning in Beam Element Model
- Saving & sharing of Working project files in .wbpz format
- Understanding Force Convergence Solution Output
- User manual
- An Unknown error occurred during solution. Check the Solver Output…..
- What is the difference between bonded contact region and fixed joint
- The solver engine was unable to converge on a solution for the nonlinear problem as constrained.
- whether have the difference between using contact and target bodies
- Defining rigid body and contact
- Colors and Mesh Display
© 2023 Copyright ANSYS, Inc. All rights reserved.