How can I create a contact region through scripting?
Pernelle Marone-Hitz
Member, Moderator, Employee Posts: 871
✭✭✭✭
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