We’re putting the final touches on our new badges platform. Badge issuance remains temporarily paused, but all completions are being recorded and will be fulfilled once the platform is live. Thank you for your patience.
General Mechanical

General Mechanical

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

Exporting Table Data to CSV in ANSYS Mechanical Script

TAGGED: 

    • Hiromu
      Subscriber

      I performed a uniaxial tensile simulation and obtained tabular data consisting of time (s), minimum value, maximum value, and average value. I would like to export this table data to a CSV file using Mechanical scripting. Could you help me with that?

    • Dennis Chen
      Subscriber

      You can use something that looks like below.   I wrote this several months ago for something else but you will want to adjust it for your purposes.   The Ansys Scripting documentation doesn't make this easy to find for us.   Hope this helps you. 

      def generate_force_reaction(analysis_system_comp):  #  read in analysis system object and write out force reaction as CSV (with space lines in the file, weird 2.7 Python BS)

          BC_interst = analysis_system_comp.Children[len(analysis_system_comp.Children)-2]  # always last BC since it's a load BS, reaction force there gives us what we want

          sol = analysis_system_comp.Solution
          force_reaction = sol.AddForceReaction()
          force_reaction.BoundaryConditionSelection = BC_interst
          force_reaction.ResultSelection = ProbeDisplayFilter.Total
          force_reaction.EvaluateAllResults()

          force_reaction.Activate()
          paneTabular=ExtAPI.UserInterface.GetPane(MechanicalPanelEnum.TabularData)
          control = paneTabular.ControlUnknown    
          num_columns = control.ColumnsCount+1
          num_rows = control.RowsCount+1
          csv_temp = []
          for row in range(1,num_rows):
              r = []
              for col in range(1,num_columns):
                  r.append(control.cell(row ,col ).Text)
              csv_temp.append(r)
          csv_output = os.path.join(result_dir, analysis_system_comp.Name + '_'+ "force_reaction"+'.csv')
          with open(csv_output, 'w') as f:
              writer = csv.writer(f)
              writer.writerows(csv_temp)

      for component in analysis_system:
          generate_force_reaction(component)
Viewing 1 reply thread
  • You must be logged in to reply to this topic.