2 Replies Latest reply on May 9, 2016 9:17 AM by Suresh Vijayan

    How I Can Select the Face of the Part By Their Name For Mating

    Suresh Vijayan

      Hi,

       

      I  Can't able to select the face Using Their Name,I Mentioned the used code for my project below,

      Kindly Guide me To select the Faces of the Part.

       

      //===========================================================================================================================

       

      swModel = SwApp.ActivateDoc("EditedShaft.SLDPRT")

              swPart = swModel

              swModel.Extension.SelectByID2("Boss-Extrude3", "BODYFEATURE", 0, 0, 0, True, 1, Nothing, 0)

       

       

              '//====SelectionCode

       

       

              swSelMgr = swModel.SelectionManager

              swFeat = swSelMgr.GetSelectedObject6(1, -1)

              swSelectData = swSelMgr.CreateSelectData()

              swModel.ClearSelection2(True)

       

       

              FaceArr = swFeat.GetFaces()

       

       

              If FaceArr Is Nothing Then Exit Sub

       

       

              For Each OneFace In FaceArr

                  SwFace = OneFace

                  SwEnt = SwFace

       

       

                  swFaceFeat = SwFace.GetFeature

       

       

                  If swFaceFeat Is swFeat Then

       

       

                      If OneFace Is FaceArr(0) Then

                          swPart.SetEntityName(SwEnt, "SelectFace2")

                          SwEnt.Select4(True, swSelectData)

                          swModel.ClearSelection2(True)

       

       

                      End If      

                  End If

              Next

              swModel.Save()

       

         '//=======Matting The Faces Of the Shaft And Coupling

       

               SwApp.ActivateDoc("AssemblySimple.sldasm")

       

         '//===Selecting the faces of the Component Using Their Name

       

               swModel.Extension.SelectByID2("SelectFace1", "FACE", 0, 0, 0, False, 0, Nothing, 0)

               swModel.Extension.SelectByID2("SelectFace2", "FACE", 0, 0, 0, True, 1, Nothing, 0)

       

          '//=======Mating the Components

       

      swAssy.AddMate3(1, 0, False, 0, 0, 0, 0, 0, 0, 0, 0, False, iErrors)

       

      //===========================================================================================================================

        • Re: How I Can Select the Face of the Part By Their Name For Mating
          Orcun Cakmak

          SelectByID2 is correct way to select with an identifier, but you need to full address like "SelectFace1@assembly-1".

            • Re: How I Can Select the Face of the Part By Their Name For Mating
              Suresh Vijayan

              Hi Orcun,

              I used  now also i can't able to select the face of the part,i Mentioned the Whole Code Below

              Kindly Give me Solution for This Problem.

              '\\====================================================================================================

               

              Public Sub AssemblyCoupling()

               

                      '//======================Declarations

               

               

                      Dim TemplateName As String = "C:\Documents and Settings\All Users\Application Data\SolidWorks\SolidWorks 2012\templates\Assembly.asmdot"

               

                      Dim swAssy As AssemblyDoc

                      Dim ShaftFilePath As String = "C:\Documents and Settings\3dcad0723\Desktop\New Folder\EditedShaft.SLDPRT"

                      Dim CouplingFilePath As String = "C:\Documents and Settings\3dcad0723\Desktop\New Folder\EditedCoupling.SLDPRT"

                      Dim shaftComp As Component2

                      Dim CouplingComp As Component2

               

                      '========Opening the New Assembly

                      swModel = SwApp.NewDocument(TemplateName, 0, 0, 0)

                      swModel.SaveAs("AssemblySimple.sldasm")

               

                      '=========Opening the parts Before Assembly

                      SwApp.OpenDoc6(ShaftFilePath, 1, 0, "", iErrors, iWarnings)

                      SwApp.OpenDoc6(CouplingFilePath, 1, 0, "", iErrors, iWarnings)

               

               

               

               

                      swAssy = SwApp.ActivateDoc("AssemblySimple.sldasm")

                      swModel.SetUserPreferenceToggle(swUserPreferenceToggle_e.swDisplayOrigins, True)

               

               

               

               

                      '=========Adding Component (Shaft part)

                      shaftComp = swAssy.AddComponent2(ShaftFilePath, 0, 0, 0)

               

               

                      '========Adding Component (Coupling Part) Three Times

               

               

                      CouplingComp = swAssy.AddComponent2(CouplingFilePath, 0.2, 0, 0)

                      'CouplingComp = swAssy.AddComponent2(CouplingFilePath, 0.5, 0.2, 0)

                      'CouplingComp = swAssy.AddComponent2(CouplingFilePath, 0.8, 0.4, 0)

               

               

                      swModel.ClearSelection2(True)

               

               

                      '===========Selecting Planes Of all Components

               

               

                      shaftComp.FeatureByName("Plane3").Select2(False, 0)

                      CouplingComp.FeatureByName("Plane2").Select2(True, 0)

               

               

                      'AddMating for planes

               

               

                      swAssy.AddMate3(0, 0, False, 0, 0, 0, 0, 0, 0, 0, 0, False, iErrors)

                      'swModel.EditRebuild3()

                      swModel.ForceRebuild3(True)

                      swModel.ClearSelection2(True)

               

               

                      '==========Selecting the Faces Of Part=========

               

               

                      ''//=======Declarations For Selection===========

               

               

                      Dim swSelMgr As SelectionMgr

                      Dim swSelectData As SelectData

                      Dim swFeat As Feature

                      Dim swFaceFeat As Feature

                      Dim FaceArr As Object

                      Dim OneFace As Object

                      Dim SwFace As Face2

                      Dim SwEnt As Entity

               

               

               

               

                      swModel = SwApp.ActivateDoc("EditedCoupling.SLDPRT")

               

               

                      swModel.Extension.SelectByID2("Cut-Extrude1", "BODYFEATURE", 0, 0, 0, True, 1, Nothing, 0)

                      swPart = swModel

               

                      '//====SelectionCode

               

               

                      swSelMgr = swModel.SelectionManager

                      swFeat = swSelMgr.GetSelectedObject6(1, -1)

                      swSelectData = swSelMgr.CreateSelectData

                      swModel.ClearSelection2(True)

               

               

                      FaceArr = swFeat.GetFaces()

               

               

                      If FaceArr Is Nothing Then Exit Sub

               

               

                      For Each OneFace In FaceArr

                          SwFace = OneFace

                          SwEnt = SwFace

               

               

                          swFaceFeat = SwFace.GetFeature

               

               

                          If swFaceFeat Is swFeat Then

               

               

                              If OneFace Is FaceArr(2) Then

               

               

                                  swPart.SetEntityName(SwEnt, "SelectFace1")

                                  SwEnt.Select4(True, swSelectData)

                                  swModel.ClearSelection2(True)

               

               

                              End If

               

               

                        

                          End If

               

               

                      Next

               

               

                      swModel.Save()

               

               

                      swModel = SwApp.ActivateDoc("EditedShaft.SLDPRT")

                      swPart = swModel

                      swModel.Extension.SelectByID2("Boss-Extrude3", "BODYFEATURE", 0, 0, 0, True, 1, Nothing, 0)

               

               

                      '//====SelectionCode

               

               

                      swSelMgr = swModel.SelectionManager

                      swFeat = swSelMgr.GetSelectedObject6(1, -1)

                      swSelectData = swSelMgr.CreateSelectData()

                      swModel.ClearSelection2(True)

               

               

                      FaceArr = swFeat.GetFaces()

               

               

                      If FaceArr Is Nothing Then Exit Sub

               

               

                      For Each OneFace In FaceArr

                          SwFace = OneFace

                          SwEnt = SwFace

               

               

                          swFaceFeat = SwFace.GetFeature

               

               

                          If swFaceFeat Is swFeat Then

               

               

                              If OneFace Is FaceArr(0) Then

                                  swPart.SetEntityName(SwEnt, "SelectFace2")

                                  SwEnt.Select4(True, swSelectData)

                                  swModel.ClearSelection2(True)

               

               

                              End If

               

               

                     

                          End If

               

               

                      Next

               

               

               

               

                      swModel.Save()

               

               

               

               

                      '//=======Matting The Faces Of the Shaft And Coupling

               

               

                      SwApp.ActivateDoc("AssemblySimple.sldasm")

               

                      swModel.Extension.SelectByID2("SelectFace1@AssemblySimple", "FACE", 0, 0, 0, False, 0, Nothing, 0)

               

                      swModel.Extension.SelectByID2("SelectFace2@AssemblySimple", "FACE", 0, 0, 0, True, 1, Nothing, 0)

               

               

               

               

               

               

                      ''=================Selecting Planes Of all Components

               

               

                      swAssy.AddMate3(1, 0, False, 0, 0, 0, 0, 0, 0, 0, 0, False, iErrors)

               

              //===================================================================================================