How to use SearchConnectionsForDuplicatePairs() ?

Pernelle Marone-Hitz
Pernelle Marone-Hitz Member, Moderator, Employee Posts: 741
First Comment First Anniversary Ansys Employee Solution Developer Community of Practice Member

Mechanical offers an option to find duplicate contacts:

Can this be used in scripting?

Tagged:

Answers

  • Pernelle Marone-Hitz
    Pernelle Marone-Hitz Member, Moderator, Employee Posts: 741
    First Comment First Anniversary Ansys Employee Solution Developer Community of Practice Member
    edited November 2023

    The function to use is SearchConnectionsForDuplicatePairs(). This method triggers the search, but does not return a list of identified objects. It just writes a warning message in Mechanical that a duplicate contact region has been found:

    However, it is possible to retrieve the contacts identified in the warning message, and suppress those contacts. Below is a script example:

    connections = ExtAPI.DataModel.Project.Model.Connections # reference connection
    duplicates = connections.SearchConnectionsForDuplicatePairs() # search duplicates
    duplicate_contacts = [] # empty list
    listMessages=ExtAPI.Application.Messages # retrieve messages in Mechanical
    for message in listMessages:
        if message.Severity == MessageSeverityType.Warning and message.DisplayString.Contains('This connection object'):
            print('There are duplicate contacts')
            duplicate_contacts.append(message.Source) # add contact to contact list
    for contact in duplicate_contacts:
        print('Suppressing ' + contact.Name)
        contact.Suppressed = True