SOLIDWORKS 2020 Launch Broadcast, on Tue, Oct 1 at 9:00 AM ET  REGISTER NOW ›

Add-in Series 2 – Create SolidWorks Add-in without the SDK [VIDEO]

Article by Adam Bridgman, CSWE created/updated January 7, 2014

Creating an add-in from the SDK is very quick and easy, but it requires the full version of visual studio to utilize. An alternative to that is to download a source project created by the SDK without modifications and then make the changes below. The files can be downloaded here.

This is how to customize an add-in:

  1. Open SwAddin.vb
  2. Change the Guid, there are many tools to generate Guids, I like this one.
  3. Change the description and title to values that you would like to see for the add-in

SwAddin

Addin

 

  1. Expand the region ISwAddin Implementation and comment out the following lines

Function ConnectToSW(ByVal ThisSW As Object, ByVal Cookie As Integer) As Boolean Implements ISwAddin.ConnectToSW

        iSwApp = ThisSW

        addinID = Cookie

       ‘ Setup callbacks

        ‘iSwApp.SetAddinCallbackInfo(0, Me, addinID)

        ‘ Setup the Command Manager

        ‘iCmdMgr = iSwApp.GetCommandManager(Cookie)

        ‘AddCommandMgr()

        ‘Setup the Event Handlers

        ‘SwEventPtr = iSwApp

        ‘openDocs = New Hashtable

        ‘AttachEventHandlers()

        ‘Setup Sample Property Manager

        ‘AddPMP()

        ConnectToSW = True

End Function

Note: you do not have to remove all of these, only remove the unnecessary items (in this example I do not require a command manager, I do not react to SolidWorks events, and I do not use a property manager page, so all of them will be removed).

 

  1. Comment out the corresponding lines for the disconnect event

       Function DisconnectFromSW() As Boolean Implements ISwAddin.DisconnectFromSW

        ‘RemoveCommandMgr()

        ‘RemovePMP()

        ‘DetachEventHandlers()

        ‘System.Runtime.InteropServices.Marshal.ReleaseComObject(iCmdMgr)

        ‘iCmdMgr = Nothing

               System.Runtime.InteropServices.Marshal.ReleaseComObject(iSwApp)

        iSwApp = Nothing

        ‘The addin _must_ call GC.Collect() here in order to retrieve all managed code pointers

        GC.Collect()

        GC.WaitForPendingFinalizers()

        GC.Collect()

        GC.WaitForPendingFinalizers()

        DisconnectFromSW = True

End Function

 

Posts related to 'Add-in Series 2 – Create SolidWorks Add-in without the SDK [VIDEO]'

Adam Bridgman, CSWE

Want to learn SOLIDWORKS?

Take a training course from our team of Certified SOLIDWORKS Experts