3 Replies Latest reply on Dec 19, 2014 8:04 PM by Subhra Maiti

    SelectByID2 doesn't work in VB.NET at all

    Charlie Fan

      Hi Guys, Below is the code of macro I used to select sketch:

       

      ==============================

      Dim swApp As Object

       

      Dim Part As Object

      Dim boolstatus As Boolean

      Dim longstatus As Long, longwarnings As Long

       

      Sub main()

       

      Set swApp = _

      Application.SldWorks

       

      Set Part = swApp.ActiveDoc

      boolstatus = Part.Extension.SelectByID2("Sketch1", "SKETCH", 0, 0, 0, False, 0, Nothing, 0)

      End Sub

      ======================================

       

      This code works perfectly in macro.

       

      However, I tried the same thing in VB.net:

       

      ===================================

          Dim swApp As SldWorks.SldWorks

       

          swApp = New SldWorks.SldWorks()
          Dim Part As Object
          Dim boolstatus As Boolean

       

          Part = swApp.ActiveDoc
         
          boolstatus = Part.Extension.SelectByID2("Sketch1", "SKETCH", 0, 0, 0, False, 0, Nothing, 0)

      ===================================

      And I compile the code in VS2013. When running, it however doesn't work and throw a "Type Mismatch error"

        • Re: SelectByID2 doesn't work in VB.NET at all
          Charlie Fan

          Can Any one kindly help find why it doesn't work?

           

          I have made a few other stand-alone exe with solidworks and they work fine.

           

          Thank you very much.

          • Re: SelectByID2 doesn't work in VB.NET at all
            Rajat Jain

            Charlie,

             

            Can you check the following code: -

             

                Dim swApp As SldWorks.SldWorks

                swApp = New SldWorks.SldWorks()

             

                if not swApp is nothing then

                      Dim Part As SldWorks.ModelDoc2

                      Dim boolstatus As Boolean

                      Part = swApp.ActiveDoc

                      If not Part is Nothing then

                          Dim swModelExtension as SldWorks.ModelDocExtension

                          swModelExtension = Part.Extension

                          If Not swModelExtension is nothing then

                              boolstatus = swModelExtension.SelectByID2("Sketch1", "SKETCH", 0, 0, 0, False, 0, Nothing, 0)         

                          End If

                            swModelExtension = nothing

                      End If

                      Part = Nothing

                Endif

              

                swApp = Nothing

             

            Hope it helps!!!

             

            Rajat Jain