Script Tip Friday- Create and export contact tool results for all time steps
The brilliant Pernelle Marone-Hitz, Lead Application Engineer at Ansys, is back again for this week's Script Tip to show us how to create and export contact tool results for all time steps. Make sure to tag her in any questions you have!
Let's break down the following scenario:
"Using ACT scripting, I would like to create a contact tool pressure result for all contacts with names ending by "YES". Then I would like to export the contact pressure results to a text file, for each time step."
The following script can be adapted to do this:
FilePath="C:\\Users\\pmaroneh\\Downloads\\"
FileExtension=r".txt"
Reference some necessary items:
领英推荐
analysis = ExtAPI.DataModel.Project.Model.Analyses[0] # change number of analysis if necessary
solution = analysis.Solution
connections = ExtAPI.DataModel.Project.Model.Connections
contactList = connections.GetChildren(DataModelObjectCategory.ContactRegion,True)
myContactList = [contact for contact in contactList if str(contact.Name).endswith("YES")]
listContactIds=[contact.ObjectId for contact in contactList] # list of ids of items in contactList
pressureList=[]
for contact in myContactList: # loop on all contacts in myContactList
newContactTool = solution.AddContactTool() # add a Contact Tool
# remove all scoped contacts
for id in listContactIds:
newContactTool.InternalObject.RemoveScopedContact(id)
# add scoping for contact
newContactTool.InternalObject.AddScopedContact(contact.ObjectId)
# add a pressure result
pressure = newContactTool.AddPressure()
# change result name
pressure.Name="ContactPressure_" + contact.Name
# store reference to result to reuse it later
pressureList.append(pressure)
resultData = analysis.GetResultsData()
dataSets=resultData.ListTimeFreq # get result sets
for resultSet in range(len(dataSets)):
displayTime=dataSets[resultSet] # select display time
unitTime='[sec]'
# loop on pressure results
for result in pressureList:
# change display time
result.DisplayTime=Quantity(str(displayTime) + unitTime)
# evaluate result
result.EvaluateAllResults()
# export result
result.ExportToTextFile(FilePath+result.Name+"_Time_"+str(displayTime)+FileExtension)
Founder at Compute Labs
2 年Last year I started a new series called "Simple Scripting for ANSYS". Here are the posts https://www.dhirubhai.net/pulse/simple-scripts-1-nameselectionbymaterial-burak-tunc-cekirdekci https://www.dhirubhai.net/pulse/simple-scripts-ansys-2-makesharedpart-burak-tunc-cekirdekci
team lead, leadership, FEA simulation and its automation/programming
2 年That 2 level loop with EvaluateAllResults() will certainly be slow for other than small models. I'd like to see more on DPF. This contact result extraction could go something like: 1-get contact element IDs from each contact object 2-use it to extract contact results via DPF That would be nice example ??
FEA Analyst | Computational Engineering Expert | Engineering Leader | Lean Six-Sigma Black Belt | Customer-focused Product Development Engineer | Team Leader | Windchill PLM Expert
2 年Check out https://github.com/lytemar/Ansys-Mechanical-Scripts. I have a similar script to this and some other useful scripts.