3 Replies Latest reply on Nov 2, 2017 9:42 AM by Jacob Corder

    Select named entity of part in assembly

    Minsik Park

      I use Solidworks 2013.

      I want to mate a PART with a SKETCH in assembly by Macro.

      I can't select entity(face) of the part in assembly.


      Imports SolidWorks.Interop.sldworks

      Imports SolidWorks.Interop.swconst

      Imports System.Runtime.InteropServices

      Imports System



      Partial Class SolidWorksMacro



          Public Sub main()

              Dim matefeature As Feature

              Dim swComp As Component2

              Dim swSelMgr As SelectionMgr

              Dim swSelData As SelectData

              Dim swPart As ModelDoc2

              Dim swFace As Face2

              Dim swEnt As Entity

              Dim bRet As Boolean

              Dim swModelDocExt As ModelDocExtension

              Dim swAssy As AssemblyDoc

              Dim errors As Integer

              Dim swDoc As ModelDoc2 = swApp.ActiveDoc


              swAssy = swDoc

              swModelDocExt = swDoc.Extension

              swComp = swAssy.GetComponentByName("PARTNAME" & "-1")

              swPart = swComp.GetModelDoc2()

              swSelMgr = swDoc.SelectionManager

              swSelData = swSelMgr.CreateSelectData

              swFace = swPart.GetEntityByName("ConcentricFACE", 2)

              swEnt = swFace




              bRet = swEnt.Select4(True, swSelData)

              bRet = swDoc.Extension.SelectByID2("Arc1@Sketch1", "EXTSKETCHSEGMENT", 0, 0, 0, True, 1, Nothing, swSelectOption_e.swSelectOptionDefault)

              matefeature = swAssy.AddMate3(swMateType_e.swMateCONCENTRIC, swMateAlign_e.swMateAlignALIGNED, False, 0, 0, 0, 0, 0, 0, 0, 0, False, errors)


          End Sub


          ''' <summary>

          ''' The SldWorks swApp variable is pre-assigned for you.

          ''' </summary>

          Public swApp As SldWorks


      End Class