AnsweredAssumed Answered

SelectByID2 doesn't work in VB.NET at all

Question asked by Charlie Fan on Dec 2, 2014
Latest reply on Dec 19, 2014 by Subhra Maiti

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"

Outcomes