How can I create a contact region through scripting?
![Pernelle Marone-Hitz](https://us.v-cdn.net/6037473/uploads/userpics/4AG2SAGAOHUA/nTB4DQJCWAJV4.jpg)
Pernelle Marone-Hitz
Member, Moderator, Employee Posts: 852
✭✭✭✭
![Ansys Employee](https://us.v-cdn.net/6037473/uploads/badges/RVRDV39KPJ91.png)
![Solution Developer Community of Practice Member](https://us.v-cdn.net/6037473/uploads/badges/274G8C56SBE6.png)
Best Answer
-
The following code can be used:
# create contact: Connections=ExtAPI.DataModel.Project.Model.Connections newContact=Connections.AddContactRegion() # modify contact type and define friction coefficient: newContact.ContactType=ContactType.Frictional newContact.FrictionCoefficient=0.2 ExtAPI.DataModel.Tree.Refresh() # refresh tree to see modifications # select contact and target faces: sourceSel=ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities) # create empty selection sourceSel.Ids=[137] # define Ids of faces to be included newContact.SourceLocation=sourceSel # apply selection to contact side targetSel=ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities) targetSel.Ids=[164] # define Ids of faces to be included newContact.TargetLocation= targetSel # apply selection to target side
0
Answers
-
Note - if the aim is to use Named Selections to define the Contact and Target region
There is no need to use script to change the scoping from Geometry selection to Named Selection, Mechanical will automatically change this if a Named Selection is used in a scoping.
To grab an existing Named Selection, one way it to use its name. GetObjectsByName returns a list of all the Mechanical objects that have a given name, if that name is unique, using the first object in the list will work:
my_NS_1 = ExtAPI.DataModel.GetObjectsByName('my_NS_1')[0] newContact.SourceLocation = my_NS_1
0