How do I export all beam probe results to .CSV files using scripting in ANSYS Mechanical?

Naveen Kumar Begari
Member Posts: 102
**
in Structures
You can export all beam probe results to CSV files using either of the two solution scripting methods below.
0
Best Answers
-
Solution - 01: Select Beam Probes in Tree
import csv import wbjn cmd = 'returnValue(GetUserFilesDirectory())' UserFilesPath = wbjn.ExecuteCommand(ExtAPI,cmd) # Selected Beam Probe Objects beamProbes = Tree.ActiveObjects for beamProbe in beamProbes: analysis = beamProbe.Parent.Parent resultsData=analysis.GetResultsData() resultSets = resultsData.ListTimeFreq wdir = analysis.WorkingDir dpString = wdir.split('_files')[1] # 'dpX\SYS\MECH' dp = dpString.split('\SY')[0] dp.Replace('\\','') export_path = UserFilesPath + dp +'_' + analysis.Name + '_' + beamProbe.Name + '.csv' AxialForce = list() Torque = list() ShearForceAtI = list() ShearForceAtJ = list() MomentAtI = list() MomentAtJ = list() vec = list() with open(export_path, 'wb') as file: writer = csv.writer(file) writer.writerow(['Axial Force','Torque','ShearForceAtI','ShearForceAtJ','MomentAtI','MomentAtJ']) for index, i in enumerate(resultSets): # InternalObject - undocumented (not supported running Linux) AxialForce = beamProbe.InternalObject.SequenceAxialForce(index) Torque = beamProbe.InternalObject.SequenceTorque(index) ShearForceAtI = beamProbe.InternalObject.SequenceShearForceAtI(index) ShearForceAtJ = beamProbe.InternalObject.SequenceShearForceAtJ(index) MomentAtI = beamProbe.InternalObject.SequenceMomentAtI(index) MomentAtJ = beamProbe.InternalObject.SequenceMomentAtJ(index) vec.append([AxialForce,Torque,ShearForceAtI,ShearForceAtJ,MomentAtI,MomentAtJ]) writer.writerows(vec)
0 -
Solution - 02: No need to select Beam Probes in Tree
import csv import wbjn import os from Ansys.ACT.Automation.Mechanical.Results.ProbeResults import BeamProbe UserFilesPath = wbjn.ExecuteCommand(ExtAPI, 'returnValue(GetUserFilesDirectory())') # Get user files directory export_path = os.path.join(UserFilesPath, 'Combined_BeamProbe_Results.csv') beamProbes = [p for p in Tree.ActiveObjects if isinstance(p, BeamProbe)] header = ['BeamProbe Name', 'Time/Freq Step', 'Axial Force', 'Torque', 'ShearForceAtI', 'ShearForceAtJ', 'MomentAtI', 'MomentAtJ'] # Header and result container all_rows = [] for probe in beamProbes: try: analysis = probe.Parent.Parent resultSets = analysis.GetResultsData().ListTimeFreq internal = probe.InternalObject for i, step in enumerate(resultSets): # Access values safely and wrap in try-except if needed axial = internal.SequenceAxialForce(i) torque = internal.SequenceTorque(i) shearI = internal.SequenceShearForceAtI(i) shearJ = internal.SequenceShearForceAtJ(i) momentI = internal.SequenceMomentAtI(i) momentJ = internal.SequenceMomentAtJ(i) all_rows.append([ probe.Name, str(step), axial, torque, shearI, shearJ, momentI, momentJ ]) except Exception as e: ExtAPI.Log.WriteMessage("Error reading data from probe '{}': {}".format(probe.Name, str(e))) with open(export_path, 'w') as f: # Write the results to CSV writer = csv.writer(f) writer.writerow(header) writer.writerows(all_rows) ExtAPI.Log.WriteMessage("CSV export completed: " + export_path)
0 -
Outputs:
Sol-01:
Sol-02:0