TAGGED: mechanical
-
-
June 21, 2025 at 1:24 pm
Hiromu
SubscriberI 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?
-
June 21, 2025 at 4:25 pm
Dennis Chen
SubscriberYou 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.
Ansys Innovation Space
Trending discussions
Top Contributors
-
3301
-
1036
-
1006
-
859
-
804
Top Rated Tags
© 2025 Copyright ANSYS, Inc. All rights reserved.
Ansys does not support the usage of unauthorized Ansys software. Please visit www.ansys.com to obtain an official distribution.