=========================== PROJECT REFERENCES =========================== SolidWorks.Interop.sldWorks SolidWOrks.Interop.swconst SolidWorks.Interop.swpublished System.Windows.Forms =========================== Main.vb =========================== Imports SolidWorks.Interop.swpublished Imports SolidWorks.Interop.sldworks Imports System.Runtime.InteropServices Imports SolidWorks.Interop.swconst Imports System.Windows.Forms Public Class Main Implements SwAddin Shared _app As SldWorks Friend Shared ReadOnly Property App As SldWorks Get Return _app End Get End Property Public Function ConnectToSW(ByVal ThisSW As Object, ByVal Cookie As Integer) As Boolean Implements SwAddin.ConnectToSW _app = ThisSW CreateUI(Cookie) Return True End Function Public Function DisconnectFromSW() As Boolean Implements SwAddin.DisconnectFromSW RemoveUI() Marshal.ReleaseComObject(_app) GC.Collect() GC.WaitForPendingFinalizers() GC.Collect() GC.WaitForPendingFinalizers() Return True End Function Private Shared Sub RegisterFunction(t As Type) Dim hklm As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.LocalMachine Dim hkcu As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.CurrentUser Dim keyname As String = "SOFTWARE\SolidWorks\Addins\{" + t.GUID.ToString() + "}" Dim addinkey As Microsoft.Win32.RegistryKey = hklm.CreateSubKey(keyname) addinkey.SetValue(Nothing, 1) addinkey.SetValue("Description", "This is my first addin") addinkey.SetValue("Title", "MyFirstAddin") keyname = "Software\SolidWorks\AddInsStartup\{" + t.GUID.ToString() + "}" addinkey = hkcu.CreateSubKey(keyname) addinkey.SetValue(Nothing, 1) End Sub Private Shared Sub UnregisterFunction(t As Type) Dim hkcu As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.CurrentUser Dim keyname As String = "SOFTWARE\SolidWorks\AddinsStartup\{" + t.GUID.ToString() + "}" hkcu.DeleteSubKey(keyname) Dim hklm As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.LocalMachine keyname = "SOFTWARE\SolidWorks\Addins\{" + t.GUID.ToString() + "}" hklm.DeleteSubKey(keyname) End Sub Sub CreateUI(cookie As Integer) App.SetAddinCallbackInfo2(0, Me, cookie) App.AddMenu(swDocumentTypes_e.swDocNONE, "My Tools", -1) App.AddMenuItem4(swDocumentTypes_e.swDocNONE, cookie, "Do Some Work@My Tools", -1, "MenuCommands(Do Some Work)", Nothing, Nothing, Nothing) App.AddMenuItem4(swDocumentTypes_e.swDocNONE, cookie, "About@My Tools", -1, "MenuCommands(About)", Nothing, Nothing, Nothing) End Sub Sub RemoveUI() App.RemoveMenu(swDocumentTypes_e.swDocNONE, "My Tools", Nothing) End Sub Sub MenuCommands(data As String) Select Case data Case "Do Some Work" MessageBox.Show("Work is being done", "My Tools") Case "About" MessageBox.Show("Written by CADSharp LLC", "My Tools") End Select End Sub End Class =========================== REGISTRATION / UNREGISTRATION =========================== Register.bat: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe /codebase "%~dp0\bin\Debug\BasicAddin.dll" PAUSE Unregister.bat C:\Windows\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe /unregister /codebase "%~dp0\bin\Debug\BasicAddin.dll" PAUSE