Created
September 6, 2018 22:49
-
-
Save CADSharp/9917d715e1dc799c0e6cae64027a236f to your computer and use it in GitHub Desktop.
Addin example with CADSharpTools
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
Get | |
Return _app | |
End Get | |
End Property | |
Public Function ConnectToSW(ThisSW As Object, Cookie As Integer) As Boolean Implements ISwAddin.ConnectToSW | |
_app = ThisSW | |
CreateUI(Cookie) | |
Return True | |
End Function | |
Public Function DisconnectFromSW() As Boolean Implements ISwAddin.DisconnectFromSW | |
RemoveUI() | |
CTAddin.DisconnectFromSWCleanup(App) | |
Return True | |
End Function | |
<ComRegisterFunction()> | |
Private Shared Sub RegisterFunction(t As Type) | |
CTAddin.RegisterAddinWithSolidWorks(t) | |
End Sub | |
<ComUnregisterFunction()> | |
Private Shared Sub UnregisterFunction(t As Type) | |
CTAddin.UnregisterAddinWithSolidWorks(t) | |
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) | |
myAboutForm.Show() | |
End Select | |
End Sub | |
End Class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment