We don’t normally write scripts for customers, but I was working on something similar recently so it didn’t take that much time for me to put something together as a derivative of what I was working on. Select the result object, and paste the script into the Mechancal script console. It will write a file to the user_files folder inside the project. It is a general script for multiple result types and analysis types. It has some error checking, but I didn’t rule out all invalid result types, especially for frequency based analysis:
# first select the result object
obj = ExtAPI.DataModel.Tree.ActiveObjects[0]
import os
dir = ExtAPI.DataModel.WorkingDir
for i in range(3):
dir = os.path.dirname(dir)
dir = os.path.join(dir, ‘user_files’)
notTypes = [
’SolutionInformation’,
’Image’,
’Figure’,
’TreeGroupingFolder’,
’Results.StressToolResults.StressTool’,
’PostContactTool’,
’FatigueTool’,
’Results.BoltToolResults.BoltTool’,
’CommandSnippet’,
’PrimaryCriterion’,
]
freqTypes =[
AnalysisType.Harmonic,
AnalysisType.Modal,
AnalysisType.Spectrum,
AnalysisType.ResponseSpectrum,
]
type = str(obj.GetType()).lstrip(‘Ansys.ACT.Automation.Mechanical.’)
if not type.find(‘.’) == -1:
type2 = type.Split(‘.’)[1]
else:
type2 = ”
if not type in notTypes and not type2 == ‘ProbeResults’:
if type2 == ‘ContactToolResults’ or type2 == ‘FatigueToolResults’ or type2 == ‘StressToolResults’ or type2 == ‘BoltToolResults’:
objName = obj.Parent.Name + ‘ ‘ + obj.Name
else:
objName = obj.Name
fileName = os.path.join(dir,objName) + ‘.txt'
an = obj
while (an != None and an.GetType() != Ansys.ACT.Automation.Mechanical.Analysis): an = an.Parent
if an != None: # found analysis
reader = an.GetResultsData()
if not reader == None:
resultPoints = reader.ListTimeFreq
if an.AnalysisType in freqTypes:
freqDomain = True
if an.AnalysisType == AnalysisType.Harmonic:
resultPoints = [resultPoints[i] for i in range(0,len(resultPoints),2)]
#if reader.HasImaginaryResults: # may be needed to check for duplicate frequency points in modal analysis and skip imaginary results
unitP = obj.Frequency.Unit
else:
freqDomain = False
unitP = obj.DisplayTime.Unit
resultSetNum = len(resultPoints)
with Transaction(): # halt display update
initial = 1
nodeValues = {}
for p in resultPoints:
if freqDomain:
obj.Frequency = Quantity(p,unitP)
else:
obj.DisplayTime = Quantity(p,unitP)
an.Solution.EvaluateAllResults()
data = obj.PlotData
if initial == 1:
initial = 0
unitR = obj.Maximum.Unit
file = open(fileName,’w’)
file.write(‘Node Number’ + ‘\t’)
nodes = data[‘Node’]
file.write(objName + ‘ ‘ + unitR + ‘ at ‘ + str(p) + ‘ ‘ + unitP + ‘\t’)
nodeValues[p] = []
for n in range(0,data[‘Values’].Count):
nodeValues[p].append(data[‘Values’][n])
file.write(‘\n’)
i = 0
for node in nodes:
file.write(str(node) + ‘\t’)
for p in resultPoints:
file.write(str(nodeValues[p][i]) + ‘\t’)
file.write(‘\n’)
i += 1
file.close()