-
-
September 5, 2023 at 10:00 am
Akshay Panchwagh
SubscriberHello!
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:
import os
import wbjn
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")n=0
ResultsOfInterest = []ResultsOfInterest.append('Temperature_Chip1')
ResultsOfInterest.append('Temperature_Chip2')
ResultsOfInterest.append('Temperature_Chip3')
ResultsOfInterest.append('Temperature_Chip4')solution=ExtAPI.DataModel.AnalysisList[0].Solution
reader = Model.Analyses[0].GetResultsData()
rsets = reader.ResultSetCountfor index, temp in enumerate(solution.Children):
if temp.GetType() == Ansys.ACT.Automation.Mechanical.Results.ThermalResults.TemperatureResult:
if temp.Name in ResultsOfInterest:
temp.Activate()
#n += 1
temp.By = Ansys.Mechanical.DataModel.Enums.SetDriverStyle.ResultSet
file_handle.write("Time[{0}];Minimum[{1}];Maximum[{1}];Average[{1}]\n".format(time_unit, temp_unit))
for rset in range(1,rsets+1):
temp.SetNumber = rset
temp.EvaluateAllResults()
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)
file_handle.write("\n")
file_handle.close()Thank you in advance.
Regards,
Akshay
-
September 6, 2023 at 9:39 am
Saumadeep
Ansys EmployeeHi Akshay
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.
Regards,
Saumadeep
-
September 6, 2023 at 11:38 am
Akshay Panchwagh
SubscriberHi Saumadeep,
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?
Regards,
Akshay
-
- 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.

Ansys Blog
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
-
7626
-
4456
-
2955
-
1427
-
1322
© 2023 Copyright ANSYS, Inc. All rights reserved.