Script Tip Friday- Create and export contact tool results for all time steps

Script Tip Friday- Create and export contact tool results for all time steps

No alt text provided for this image

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:

  • Define path to where results will be exported:

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        

  • In connections, find children that are contacts and create a list of these contact regions:

contactList = connections.GetChildren(DataModelObjectCategory.ContactRegion,True)        

  • From this list, create another list for contacts which name end by "YES":

myContactList = [contact for contact in contactList if str(contact.Name).endswith("YES")]        

  • For contacts in myContactList, create a contact tool / pressure result:

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)        

  • Loop on all time steps and export results:

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)        

Do YOU have a Script Tip? We'd love to hear from you! Leave us a comment and someone from the team will reach out to you directly and feature you on our next Script Tip Friday.

Pavel Urubcik

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 ??

回复
Mark R. Lytell

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.

要查看或添加评论,请登录

Ansys Structures的更多文章

社区洞察

其他会员也浏览了