Go To Contacts For Selected Entities

This code is similar to Go To -> Contacts For Selected Bodies with the difference that you can select a geometry entity (Body, face, edge,..) and go to contacts for selected entities. Select e.g. a face/multiple faces and run the script to find the specific contacts for those entities! In this example, one face is selected and the contacts that includes that face is selected in the Tree.

Transparent Transparent

clr.AddReference("Ans.UI.Toolkit")
clr.AddReference("Ans.UI.Toolkit.Base")
from Ansys.UI.Toolkit import *

entity = ExtAPI.SelectionManager.CurrentSelection.Ids
entity_selectionInfo = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
entity_selectionInfo.Ids = entity
contactSearchId = entity_selectionInfo.Ids

all_contacts = DataModel.GetObjectsByType(DataModelObjectCategory.ContactRegion)
contact_found = []; contact_region_ids = []
for contact in all_contacts:
    for contId in contact.SourceLocation.Ids: contact_region_ids.append(contId)
    for targId in contact.TargetLocation.Ids: contact_region_ids.append(targId)
    for i in contactSearchId:
        if i in contact_region_ids: contact_found.append(contact)
    contact_region_ids = []
if contact_found.Count > 0: Tree.Activate(contact_found)
else: MessageBox.Show("No contacts defined on selected geometry!")