Set automatic connections through scripting

Options
Pernelle Marone-Hitz
Pernelle Marone-Hitz Member, Moderator, Employee Posts: 813
First Comment First Anniversary Ansys Employee Solution Developer Community of Practice Member
edited June 2023 in Structures

How can we set automatic contacts through scripting in Mechanical?

Tagged:

Answers

  • Pernelle Marone-Hitz
    Pernelle Marone-Hitz Member, Moderator, Employee Posts: 813
    First Comment First Anniversary Ansys Employee Solution Developer Community of Practice Member
    Answer ✓
    Options

    The following function can be used:

    def SetContacts(analysis):        
        try:
            ExtAPI.Log.WriteMessage("Automation of Contacts Definition")    
            
            connections =  ExtAPI.DataModel.Project.Model.Connections      
            # delete existing contacts
            for connection in connections.Children:
                if connection.DataModelObjectCategory==DataModelObjectCategory.ConnectionGroup:
                    connection.Delete()
            
            # create automatically generated contacts    
            contactGroup=connections.AddConnectionGroup()
            contactGroup.ToleranceType=0 # for slider type
            contactGroup.ToleranceSlider=70 # tolerance    
            contactGroup.CreateAutomaticConnections()       
            ExtAPI.Log.WriteMessage("End of Automation of Contacts Definition")  
        except:
            ExtAPI.Log.WriteMessage("Error : Exception in SetContacts()")
    
  • Ayush Kumar
    Ayush Kumar Member, Moderator, Employee Posts: 416
    First Anniversary Ansys Employee Solution Developer Community of Practice Member First Answer
    Answer ✓
    Options

    We can also skip the contact group creation. The following line does everything automatically:

    Model.Connections.CreateAutomaticConnections()