We have an exciting announcement about badges coming in May 2025. Until then, we will temporarily stop issuing new badges for course completions and certifications. However, all completions will be recorded and fulfilled after May 2025.
General Mechanical

General Mechanical

Topics related to Mechanical Enterprise, Motion, Additive Print and more.

Automating extraction of data at different substeps

    • afm
      Subscriber

      Hello,

       

      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 point
      counter = 0
      for 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 = 3
                  if counter == 1:
                      fileName = "{}\Y Coordinate of Deformation [YLOC]\{}_YLOC.txt".format(save_location,row_number)
                      result.ExportToTextFile(fileName)
                      counter = 2
                  if counter == 0:
                      fileName = "{}\X Coordinate of Deformation [XLOC]\{}_XLOC.txt".format(save_location,row_number)
                      result.ExportToTextFile(fileName)
                      counter = 1

       

    • Shashidhar Reddy
      Ansys Employee

       

       

      Hi 

      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.

      Using ACT, how can I create a result for each time step and export result to a text file? — Community Forum

       

       

      • Store link to solution

        1. solu=ExtAPI.DataModel.Project.Model.Analyses[0].Solution
      • Obtain list of time sets

        1. ResData=ExtAPI.DataModel.Project.Model.Analyses[0].GetResultsData()
        2. DataSets=ResData.ListTimeFreq
      • Loop through data sets

        1. for DataSet in range(len(DataSets)):
      • Define display time

        1. DisplayTime=DataSets[DataSet]
        2. UnitTime='[sec]'
      • Insert result and evaluate

        1. result=solu.AddMaximumPrincipalStress()
        2. result.DisplayTime=Quantity(str(DisplayTime) + UnitTime)
        3. solu.EvaluateAllResults()
      • Export result to text file

        1. FilePath=r”D:\Test\Export”
        2. FileExtension=r”.txt”
        3. result.ExportToTextFile(True,FilePath+str(DisplayTime)+FileExtension)

       

       

      Hope it helps.

      Thank you

       

      Regards

      Shashidhar, PhD

       

       

    • afm
      Subscriber

      Hello,

      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.

Viewing 2 reply threads
  • You must be logged in to reply to this topic.