


{"id":429965,"date":"2025-04-24T19:01:55","date_gmt":"2025-04-24T19:01:55","guid":{"rendered":"https:\/\/innovationspace.ansys.com\/forum\/forums\/topic\/automating-extraction-of-data-at-different-substeps\/"},"modified":"2025-04-24T19:01:55","modified_gmt":"2025-04-24T19:01:55","slug":"automating-extraction-of-data-at-different-substeps","status":"publish","type":"topic","link":"https:\/\/innovationspace.ansys.com\/forum\/forums\/topic\/automating-extraction-of-data-at-different-substeps\/","title":{"rendered":"Automating extraction of data at different substeps"},"content":{"rendered":"<p>&lt;p&gt;Hello,&lt;\/p&gt;&lt;p&gt;&nbsp;&lt;\/p&gt;&lt;p&gt;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.&lt;\/p&gt;&lt;p&gt;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).&nbsp;&lt;\/p&gt;&lt;p&gt;&nbsp;&lt;\/p&gt;&lt;div&gt;# &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; READ ME FIRST &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;&lt;\/div&gt;&lt;div&gt;# MAKE SURE THAT THE USER DEFINE RESULTS HAS LOC_DEFX ***FIRST***&lt;\/div&gt;&lt;div&gt;# Second will be LOC_DEFY, third will be LOC_DEFZ&lt;\/div&gt;&lt;div&gt;&nbsp;&lt;\/div&gt;&lt;div&gt;#input the row number below (for naming)&lt;\/div&gt;&lt;div&gt;row_number = &#8216;400&#8217;&lt;\/div&gt;&lt;div&gt;&nbsp;&lt;\/div&gt;&lt;div&gt;# input the file path for where you want the files to export to&nbsp;&lt;\/div&gt;&lt;div&gt;# (do not select 13mm or 18mm folder, stop at skin test folder)&lt;\/div&gt;&lt;div&gt;save_location = r&#8221;C:\\User\\Downloads&#8221;&lt;\/div&gt;&lt;div&gt;&nbsp;&lt;\/div&gt;&lt;div&gt;# No need to edit anything below this point&lt;\/div&gt;&lt;div&gt;counter = 0&lt;\/div&gt;&lt;div&gt;for analysis in ExtAPI.DataModel.Project.Model.Analyses:&lt;\/div&gt;&lt;div&gt;&nbsp; &nbsp; for result in analysis.Solution.Children:&lt;\/div&gt;&lt;div&gt;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&lt;\/div&gt;&lt;div&gt;&nbsp; &nbsp; &nbsp; &nbsp; if result.GetType().Equals(Ansys.ACT.Automation.Mechanical.Results.DeformationResults.TotalDeformation):&lt;\/div&gt;&lt;div&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fileName = &#8220;{}\\Deformation [D]\\{}_D.txt&#8221;.format(save_location,row_number)&lt;\/div&gt;&lt;div&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result.ExportToTextFile(fileName)&lt;\/div&gt;&lt;div&gt;&nbsp; &nbsp; &nbsp; &nbsp; if result.GetType().Equals(Ansys.ACT.Automation.Mechanical.Results.StrainResults.EquivalentElasticStrainRST):&lt;\/div&gt;&lt;div&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fileName = &#8220;{}\\Strain\\{}_SN.txt&#8221;.format(save_location,row_number)&lt;\/div&gt;&lt;div&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result.ExportToTextFile(fileName)&lt;\/div&gt;&lt;div&gt;&nbsp; &nbsp; &nbsp; &nbsp; if result.GetType().Equals(Ansys.ACT.Automation.Mechanical.Results.StrainResults.MaximumPrincipalElasticStrain):&lt;\/div&gt;&lt;div&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fileName = &#8220;{}\\Principle Strain [PS]\\{}_PS.txt&#8221;.format(save_location,row_number)&lt;\/div&gt;&lt;div&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result.ExportToTextFile(fileName)&lt;\/div&gt;&lt;div&gt;&nbsp; &nbsp; &nbsp; &nbsp; if result.GetType().Equals(Ansys.ACT.Automation.Mechanical.Results.StressResults.EquivalentStress):&lt;\/div&gt;&lt;div&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fileName = &#8220;{}\\Stress [SS]\\{}_SS.txt&#8221;.format(save_location,row_number)&lt;\/div&gt;&lt;div&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result.ExportToTextFile(fileName)&lt;\/div&gt;&lt;div&gt;&nbsp; &nbsp; &nbsp; &nbsp; if result.GetType().Equals(Ansys.ACT.Automation.Mechanical.Results.UserDefinedResult):&lt;\/div&gt;&lt;div&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if counter == 2:&lt;\/div&gt;&lt;div&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fileName = &#8220;{}\\Z Coordinate of Deformation [ZLOC]\\{}_ZLOC.txt&#8221;.format(save_location,row_number)&lt;\/div&gt;&lt;div&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result.ExportToTextFile(fileName)&lt;\/div&gt;&lt;div&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; counter = 3&lt;\/div&gt;&lt;div&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if counter == 1:&lt;\/div&gt;&lt;div&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fileName = &#8220;{}\\Y Coordinate of Deformation [YLOC]\\{}_YLOC.txt&#8221;.format(save_location,row_number)&lt;\/div&gt;&lt;div&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result.ExportToTextFile(fileName)&lt;\/div&gt;&lt;div&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; counter = 2&lt;\/div&gt;&lt;div&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if counter == 0:&lt;\/div&gt;&lt;div&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fileName = &#8220;{}\\X Coordinate of Deformation [XLOC]\\{}_XLOC.txt&#8221;.format(save_location,row_number)&lt;\/div&gt;&lt;div&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result.ExportToTextFile(fileName)&lt;\/div&gt;&lt;div&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; counter = 1&lt;\/div&gt;&lt;p&gt;&nbsp;&lt;\/p&gt;<\/p>\n","protected":false},"template":"","class_list":["post-429965","topic","type-topic","status-publish","hentry","topic-tag-automationACT-1","topic-tag-python-ironpython-1","topic-tag-ansys-meshing-python-script"],"aioseo_notices":[],"acf":[],"custom_fields":[{"0":{"_bbp_forum_id":["27791"],"_bbp_topic_id":["429965"],"_bbp_subscription":["544544","49782"],"_bbp_author_ip":["128.235.159.33"],"_bbp_last_reply_id":["430224"],"_bbp_last_active_id":["430224"],"_bbp_last_active_time":["2025-04-28 15:42:59"],"_bbp_reply_count":["2"],"_bbp_reply_count_hidden":["0"],"_bbp_voice_count":["2"],"_bbp_engagement":["544544","49782"],"_btv_view_count":["309"],"_bbp_topic_status":["unanswered"]},"test":"afmnjit-edu"}],"_links":{"self":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/topics\/429965","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/topics"}],"about":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/topics\/429965\/revisions"}],"wp:attachment":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/media?parent=429965"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}