Greetings Maks!
I finally found a solution which is working according to my, or our liking. I am able to export the results in Tablular Data for all the selected Solution Objects while the Design Points update through Workbench. I used a different script which does not need to access the User Interface Pane command to read the results. From what I understood, the UserInterface.GetPane command needs the Mechanical GUI to be open in order to work. So I found a workaround after interacting with ANSYS employees regarding this problem. You also don't need to make any changes in the Property Provider in order to get the active Design Point number. Initially while executing this script, Workbench used to crash. So I updated it from 2022 R2 to 2023 R2. And now it works perfectly.
I am posting the script here. Let me know if it works for you. I will suggest to use the latest version of Workbench for this script to work. Otherwise it will crash.
Also, the main parts of the code which I thought were necessary for successful execution of the script have been highlighted in bold. Rest of the parts you can edit according to your needs.
####Things to note:
###Create a Python Code Object in Solution
###Set the Target Callback under Definition of the Python Code Object to 'After Post'
###Paste the below written code into the Python Code Object
###Connect the Python Code Object
#If you want this code to run for multiple design points in a Parameter Set, ensure that the Python Code Object stays connected every time Mechanical is opened. This can be ensured in Workbench as follows:
#Workbench -> Tools -> Options -> Mechanical -> Check the box "Connect/Run Python Code Objects When Mechanical is launched"
import os
import wbjn
import csv
#This command returns the user files directory where the CSV files will get stored. It can be changed to any other target folder of choice.
userfilesdir = wbjn.ExecuteCommand(ExtAPI,"""returnValue(GetUserFilesDirectory())""")
#This command returns the active design point from the Parameter Set
dpn=wbjn.ExecuteCommand(ExtAPI,"returnValue(a+Parameters.GetActiveDesignPoint().Name)",a="DP")
file_name = os.path.join(userfilesdir, dpn+"data.csv")
file_handle = open(file_name, "w")
#Returns units of the desired quantities which you want to be written in the CSV file. Write the desired quantity name in string format.
time_unit = ExtAPI.DataModel.CurrentUnitFromQuantityName("Time")
temp_unit = ExtAPI.DataModel.CurrentUnitFromQuantityName("Temperature")
#Create an empty list here where target result quantities will be stored.
#Append the names of the target result quantities in string format.
ResultsOfInterest = []
ResultsOfInterest.append()
#Accesses the solution of the project through ACT API
solution=ExtAPI.DataModel.AnalysisList[0].Solution
#Accesses the counts of time steps through result object
### VERY IMPORTANT: THE DEFINITION OF THE DESIRED SOLUTION OBJECT MUST BE SET TO "RESULT SET". THIS CAN BE DONE AS FOLLOWS ###
### SOLUTION -> DESIRED SOLUTION OBJECT(S) -> DEFINITION -> BY -> RESULT SET ###
### IF THIS IS NOT DONE; THE CODE WON'T WORK ###
reader = Model.Analyses[0].GetResultsData()
rsets = reader.ResultSetCount
#This loop here loops through the Solution Objects one by one. It verifies if the name of the solution object is
#present in the list created before. If yes, it activates that solution object. After that, the code reads
#all the result values for all the time steps in the particular solution object(s) and saves these results into the CSV file
#which was defined previously
for sol_obj in solution.Children:
if sol_obj.GetType() == Ansys.ACT.Automation.Mechanical.Results.ThermalResults.TemperatureResult:
if sol_obj.Name in ResultsOfInterest:
sol_obj.Activate()
#n += 1
sol_obj.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):
sol_obj.SetNumber = rset
sol_obj.EvaluateAllResults()
result_avg = sol_obj.Average
result_max = sol_obj.Maximum
result_min = sol_obj.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()
Let me know if you are able to run it. The only drawback is that the results get stored in string format along with their units in the CSV file. But that is something that can be dealt with later using Python, or any other programming tool. As I said, let me know how it works.
Regards,
Akshay