Public Sub SelectComponentFaceByName(componentName As String, faceName As String) Dim swBody As SldWorks.Body2 Dim swSelData As SldWorks.SelectData Dim currentFaceName As String Set swSelData = swSelMgr.CreateSelectData ' Get the component body Set swBody = swcomponent.GetBody() If (swBody Is Nothing) Then swApp.SendMsgToUser "Component body unavailable." swApp.SendMsgToUser "Make sure component is not lightweight or suppressed." Exit Sub End If Debug.Print "Traversing faces on component's body..." Set swFace = swBody.GetFirstFace Do While Not swFace Is Nothing currentFaceName = swModel.GetEntityName(swFace) If (currentFaceName = faceName) Then ' Select the face swFace.Select4 False, swSelData Debug.Print " Name of currently selected face; should match name of previously selected face: " & currentFaceName Exit Do End If Set swFace = swFace.GetNextFace Loop ' Subsequent code might select a second face, ' edge, or feature, and then mate the two ' items using AssemblyDoc::AddMate5 End Sub _________________________________________________________________________________ 'selectionne le plan d'appui de l'élément à contraindre Set swSelMgr = swModel.SelectionManager ' Create the name of the mate and the names of the planes to use for the mate MateName = "Cote_" + strCompName 'Sélection de la pièce à contraindre boolstatus = swDocExt.SelectByID2("", "COMPONENT", 0.5, 0, 0.5, False, 0, Nothing, 0) Set swcomponent = swSelMgr.GetSelectedObject6(1, -1) componentName = swcomponent.Name2 'sélection d'une face quelconque de la pièce boolstatus = swDocExt.SelectByID2("", "FACE", 0.5, 0, 0.5, False, 0, Nothing, 0) Set swFace = swSelMgr.GetSelectedObject6(1, -1) boolstatus = swModel.SelectedFaceProperties(0, 0, 0, 0, 0, 0, 0, True, "SideFace") faceName = swModel.GetEntityName(swFace) ' Recherche de la face (voir ci dessus) SelectComponentFaceByName componentName, "Fond" ' Fond est le nom de la face à séléctionner SecondSelection = "Plan de face@" + AssemName boolstatus = swDocExt.SelectByID2(SecondSelection, "PLANE", 0, 0, 0, True, 1, Nothing, swSelectOptionDefault) ' Add the mate Set matefeature = swAssy.AddMate5(0, 1, False, 0, 0, 0, 0, 0, 0, 0, 0, False, False, 0, mateError) matefeature.Name() = MateName