7 Replies Latest reply on Apr 7, 2014 2:18 AM by Stanley Sentoso

    Asking about SelectByID2 function

    Stanley Sentoso

      Hi All,


      I'm a newbie in SolidWorks API and I have a question about the strange behaviour of SelectByID2 function. Below is the scanario:

      First of All, I created a sketch on solidworks and named it with "My_Sketch". Next, I created a very simple VBA macro to find (select) that sketch as following script


      Option Explicit

      Dim obApp As SldWorks.SldWorks

      Dim obPart As ModelDoc2

      Dim bStat As Boolean


      Sub main()

          Set obApp = Application.SldWorks

          Set obPart = obApp.ActiveDoc


          bStat = obPart.Extension.SelectByID2("My_Sketch", "SKETCH", 0, 0, 0, False, 0, Nothing, 0)

          MsgBox "Return value is " & CStr(bStat)     ' Prompt the return value


          If bStat = True Then

              MsgBox "System found the sketch!"


              MsgBox "System couldn't locate the sketch!"

          End If


      End Sub


      when I run that script, it prompted me "Return value is True" and "System couldn't locate the sketch!"




      By right, if bStat is True, it will prompt "System found the sketch!" but it didn't.

      Is it a bug or have I implemented wrongly ?


      FYI, I used SolidWorks 2013