-
-
April 24, 2025 at 7:01 pm
afm
SubscriberHello,
I am trying to export deformation, stress, and strain data at different substeps using python in Ansys. This is my current code which exports the selected substep.
I am trying to create a loop that goes through each of the substeps and exports the data from each substep into a folder based on the data type(deformation, stress, strain).
# ----------------------- READ ME FIRST -----------------------# MAKE SURE THAT THE USER DEFINE RESULTS HAS LOC_DEFX ***FIRST***# Second will be LOC_DEFY, third will be LOC_DEFZ#input the row number below (for naming)row_number = '400'# input the file path for where you want the files to export to# (do not select 13mm or 18mm folder, stop at skin test folder)save_location = r"C:\User\Downloads"# No need to edit anything below this pointcounter = 0for analysis in ExtAPI.DataModel.Project.Model.Analyses:for result in analysis.Solution.Children:if result.GetType().Equals(Ansys.ACT.Automation.Mechanical.Results.DeformationResults.TotalDeformation):fileName = "{}\Deformation [D]\{}_D.txt".format(save_location,row_number)result.ExportToTextFile(fileName)if result.GetType().Equals(Ansys.ACT.Automation.Mechanical.Results.StrainResults.EquivalentElasticStrainRST):fileName = "{}\Strain\{}_SN.txt".format(save_location,row_number)result.ExportToTextFile(fileName)if result.GetType().Equals(Ansys.ACT.Automation.Mechanical.Results.StrainResults.MaximumPrincipalElasticStrain):fileName = "{}\Principle Strain [PS]\{}_PS.txt".format(save_location,row_number)result.ExportToTextFile(fileName)if result.GetType().Equals(Ansys.ACT.Automation.Mechanical.Results.StressResults.EquivalentStress):fileName = "{}\Stress [SS]\{}_SS.txt".format(save_location,row_number)result.ExportToTextFile(fileName)if result.GetType().Equals(Ansys.ACT.Automation.Mechanical.Results.UserDefinedResult):if counter == 2:fileName = "{}\Z Coordinate of Deformation [ZLOC]\{}_ZLOC.txt".format(save_location,row_number)result.ExportToTextFile(fileName)counter = 3if counter == 1:fileName = "{}\Y Coordinate of Deformation [YLOC]\{}_YLOC.txt".format(save_location,row_number)result.ExportToTextFile(fileName)counter = 2if counter == 0:fileName = "{}\X Coordinate of Deformation [XLOC]\{}_XLOC.txt".format(save_location,row_number)result.ExportToTextFile(fileName)counter = 1 -
April 25, 2025 at 1:16 am
Shashidhar Reddy
Ansys EmployeeHi
I request you to post scripting (ACT/python) related queries in the developer forum.
You can go through following script to loop it through different substeps.
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)
Hope it helps.
Thank you
Regards
Shashidhar, PhD
-
April 28, 2025 at 3:42 pm
afm
SubscriberHello,
Thank you for your quick reply. When I try this, I receive the error message that "Solution Information" object has no attribute "Display Time". Could you please advise me on why this is occuring?
Thank you.
-
- You must be logged in to reply to this topic.
-
3019
-
970
-
857
-
761
-
599
© 2025 Copyright ANSYS, Inc. All rights reserved.