Tring to make automatic contact generation

Happy
Happy Member Posts: 2 **

Below code I have made for automatic contact generation, but the problem is I have to give input as reference ID of surfaces very precisely which is time consuming. Even I go for name selection again it will create hectic in giving name. So is there any another method in which I can generate number of contacts precisely with proper formulation and settings.

frictional_ids = {761:250962,866:250945,971:250994,1076:250980,76388:251015,78078:251104}
frictional_add_off_NR = {433576:480234,433603:480434}
Damping_stablization_element = [433576,433603]
frictional_add_off_RE = {(113899,113914):433577,(72595,72600):[113789,113790],433604:[72616,72607]}
bonded_ids = {(110988,110985):[114061,114062],(111302,111299):[114054,114053],(111142,111145):[114070,114069]}
print("total number of contacts is", len(frictional_ids)+ len(bonded_ids) + len(frictional_add_off_NR) +len(frictional_add_off_RE))

Connections = ExtAPI.DataModel.Project.Model.Connections
newContact = Connections.AddConnectionGroup()

def frict_setting():
con_region = newContact.AddContactRegion()
con_region.ContactFormulation = ContactFormulation.AugmentedLagrange
con_region.Behavior = ContactBehavior.Asymmetric
con_region.ContactType = ContactType.Frictional
con_region.FrictionCoefficient = 0.15
con_region.PinballRegion = ContactPinballType.Radius
con_region.PinballRadius = Quantity("1[mm]")
return con_region

def frict_set_add_to_touch():
con_region = frict_setting()
con_region.InterfaceTreatment = ContactInitialEffect.AdjustToTouch
return con_region

def frict_set_add_off_NR():
con_region = frict_setting()
con_region.InterfaceTreatment = ContactInitialEffect.AddOffsetNoRamping
con_region.UserOffset = Quantity('0.5[mm]')
return con_region

def frict_set_add_off_RE():
con_region = frict_setting()
con_region.InterfaceTreatment = ContactInitialEffect.AddOffsetRampedEffects
con_region.UserOffset = Quantity('0.5[mm]')
return con_region

def bonded_contacts():
con_region = newContact.AddContactRegion()
con_region.ContactFormulation = ContactFormulation.MPC
con_region.Behavior = ContactBehavior.Asymmetric
con_region.ContactType = ContactType.Bonded
con_region.PinballRegion = ContactPinballType.Radius
con_region.PinballRadius = Quantity(".5[mm]")
return con_region

def set_source_and_target(con_region, source, target):
source_sel = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
target_sel = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
source_sel.Ids = list(source) if isinstance(source, tuple) else [source]
target_sel.Ids = target if isinstance(target, list) else [target]
con_region.SourceLocation = source_sel
con_region.TargetLocation = target_sel

for source, target in frictional_ids.items():
con_region = frict_set_add_to_touch()
set_source_and_target(con_region, source, target)

for source, target in frictional_add_off_NR.items():
con_region = frict_set_add_off_RE()
if source in Damping_stablization_element:
con_region.StabilizationDampingFactor = 0.005
set_source_and_target(con_region, source, target)
set_source_and_target(con_region, source, target)

for source, target in frictional_add_off_RE.items():
con_region = frict_set_add_off_RE()

set_source_and_target(con_region, source, target)

for source, target in bonded_ids.items():
con_region = bonded_contacts()
set_source_and_target(con_region, source, target)