Skip to main content

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

| 06.10.2022

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.

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:

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
  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:
      # add scoping for contact
      # add a pressure result
      pressure = newContactTool.AddPressure()
      # change result name
      pressure.Name="ContactPressure_" + contact.Name
      # store reference to result to reuse it later
  • 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
      # loop on pressure results
      for result in pressureList:    
          # change display time 
          result.DisplayTime=Quantity(str(displayTime) + unitTime)
          # evaluate result
          # export result