Split Contact
Original Contact Region includes 4 Contact Faces and 1 Target Face. Select a Contact Region in the Tree. Run the script to split contact and suppress the original.
clr.AddReference("Ans.UI.Toolkit")
clr.AddReference("Ans.UI.Toolkit.Base")
from Ansys.UI.Toolkit import *
ConnectionsObject = Model.Connections
ContactRegion = Tree.FirstActiveObject
ContactScoping = ContactRegion.SourceLocation
TargetScoping = ContactRegion.TargetLocation
ContactIDS = ContactScoping.Ids
TargetIDS = TargetScoping.Ids
GroupContacts = list()
if ContactIDS.Count > 1 and TargetIDS.Count > 1: print MessageBox.Show("Not Supported. One side (Contact or Target) must count to exactly 1 scoped entity.")
if ContactIDS.Count > TargetIDS.Count:
TargetID = TargetIDS[0]
TargetSelection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
TargetSelection.Ids = [TargetID]
counter = 1
for ContactID in ContactIDS:
NewSelection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
NewSelection.Ids = [ContactID]
if counter == 1:
NewContactRegion = ConnectionsObject.AddContactRegion()
NewConnectionsGroup = NewContactRegion.Parent
counter += 1
else: NewContactRegion = NewConnectionsGroup.AddContactRegion()
NewContactRegion.SourceLocation = NewSelection
NewContactRegion.TargetLocation = TargetSelection
GroupContacts.append(NewContactRegion)
else:
ContactID = ContactIDS[0]
ContactSelection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
ContactSelection.Ids = [ContactID]
counter = 1
for TargetID in TargetIDS:
NewSelection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
NewSelection.Ids = [TargetID]
if counter == 1:
NewContactRegion = ConnectionsObject.AddContactRegion()
NewConnectionsGroup = NewContactRegion.Parent
counter += 1
else: NewContactRegion = NewConnectionsGroup.AddContactRegion()
NewContactRegion.TargetLocation = NewSelection
NewContactRegion.SourceLocation = ContactSelection
GroupContacts.append(NewContactRegion)
NewConnectionsGroup.Name = str(ContactRegion.Name) + " splitted into " + str(GroupContacts.Count) + " contacts"
ContactRegion.Suppressed = True