Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Addin example with CADSharpTools
Class Constants
Friend Const MenuItem_Command1 As String = "Command 1"
Friend Const MenuItem_Command2 As String = "Command 2"
Friend Const MenuItem_Command3 As String = "Command 3"
Friend Const MenuItem_About As String = "About"
Friend Const AboutText As String = "Command 1 is available in part documents." + vbNewLine +
"Command 2 is available in part and assembly documents." + vbNewLine +
"Command 3 is available in all documents."
Friend Const MenuCallback As String = "RunMenuCommands"
End Class
Imports SolidWorks.Interop.swpublished
Imports SolidWorks.Interop.sldworks
Imports System.Runtime.InteropServices
Imports CADSharpTools
Imports CADSharpTools.CTAddin
Imports CADSharpTools.CTAddin.CTMenu
<Guid("e2d74c00-b201-4058-98f5-7439c403611f")> <ComVisible(True)>
Public Class Main
Implements SwAddin
Private ctMenu As CTMenu
Shared _app As SldWorks
Friend Shared ReadOnly Property App As SldWorks
Return _app
End Get
End Property
Public Function ConnectToSW(ThisSW As Object, Cookie As Integer) As Boolean Implements ISwAddin.ConnectToSW
_app = ThisSW
Return True
End Function
Public Function DisconnectFromSW() As Boolean Implements ISwAddin.DisconnectFromSW
Return True
End Function
Private Shared Sub RegisterFunction(t As Type)
End Sub
Private Shared Sub UnregisterFunction(t As Type)
End Sub
Private Sub CreateUI(cookie As Integer)
Dim menuItem1 As New CTMenuItem(Constants.MenuItem_Command1, CTDocTypes.Part)
Dim menuItem2 As New CTMenuItem(Constants.MenuItem_Command2, CTDocTypes.Part + CTDocTypes.Assembly)
Dim menuItem3 As New CTMenuItem(Constants.MenuItem_Command3, CTDocTypes.Drawing)
Dim menuItem4 As New CTMenuItem(Constants.MenuItem_About, CTDocTypes.All)
ctMenu = New CTMenu(New List(Of CTMenuItem) From {menuItem1, menuItem2, menuItem3, menuItem4})
ctMenu.Create(App, Me, cookie, Nothing)
End Sub
Private Sub RemoveUI()
If ctMenu IsNot Nothing Then ctMenu.Remove(App)
End Sub
Sub RunMenuCommands(data As String)
Select Case data
Case Constants.MenuItem_Command1
CTUtility.ShowMessage("Action 1")
Case Constants.MenuItem_Command2
CTUtility.ShowMessage("Action 2")
Case Constants.MenuItem_Command3
CTUtility.ShowMessage("Action 3")
Case Constants.MenuItem_About
Dim myAboutForm As New CTAboutForm(Constants.AboutText)
End Select
End Sub
End Class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment