Add Buttons to Task Pane (VBA)
This example shows how to add standard SOLIDWORKS and custom buttons to the
Task Pane.
Module
'----------------------------------------------------------------
' Preconditions:
' 1. SOLIDWORKS is running.
' 2. Copy the custom button images, localHelp.bmp and save.png, from
' install_dir\samples\tutorial\api to this macro's folder.
'
' Postconditions:
' 1. The Task Pane, with Microsoft Calendar control loaded, opens
' with the specified SOLIDWORKS standard and custom buttons at the
' top of the pane.
' 2. Click each button from left to right. A message box is displayed
' confirming the button click. Additionall,y clicking the Close
' button prompts you to remove the control from the Task Pane.
'-----------------------------------------------------------------
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swTaskPane As SldWorks.TaskpaneView
Dim result As Boolean
Dim folder As String
Dim bitmap As String
Dim toolTip As String
Dim ctrlName As String
Dim ctrlLicKey As String
Public buttonIdx As Integer
Dim swTaskpaneEvents As New Class1
Sub main()
Set swApp = Application.SldWorks
folder = swApp.GetCurrentMacroPathFolder + "\"
' Use default image for Task Pane tab
bitmap = ""
toolTip = "Microsoft Calendar"
ctrlName = "MSCAL.Calendar"
ctrlLicKey = ""
Set swTaskPane = swApp.CreateTaskpaneView2(bitmap, toolTip)
' Add standard and custom buttons to Task Pane
result = swTaskPane.AddCustomButton(folder & "localHelp.bmp", "Help (custom bmp)")
result = swTaskPane.AddCustomButton(folder & "save.png", "Save (custom png)")
result = swTaskPane.AddStandardButton(swTaskPaneBitmapsOptions_Next, "Next (standard)")
result = swTaskPane.AddStandardButton(swTaskPaneBitmapsOptions_Back, "Back (standard)")
result = swTaskPane.AddStandardButton(swTaskPaneBitmapsOptions_Ok, "OK (standard)")
result = swTaskPane.AddStandardButton(swTaskPaneBitmapsOptions_Close, "Close (standard)")
' Add control to Task Pane for the buttons
swTaskPane.AddControl ctrlName, ctrlLicKey
' Set up events
Set swTaskpaneEvents.swTaskPane = swTaskPane
End Sub
Class Module
Option Explicit
Public WithEvents swTaskPane As SldWorks.TaskpaneView
Private Function swTaskPane_TaskPaneActivateNotify() As Long
If (swTaskPane.GetButtonState(0) = False) Then
For buttonIdx = 0 To 20
swTaskPane.SetButtonState(buttonIdx) = True
Next
Else
For buttonIdx = 0 To 20
swTaskPane.SetButtonState(buttonIdx) = False
Next
End If
End Function
Private Function swTaskPane_TaskPaneDestroyNotify() As Long
MsgBox ("Remove control from Task Pane?")
End Function
Private Function swTaskPane_TaskPaneToolbarButtonClicked(ByVal ButtonIndex As Long) As Long
Select Case (ButtonIndex + 1)
Case 1
MsgBox "Help (custom bmp) button clicked."
Case 2
MsgBox "Save (custom png) button clicked."
Case 3
MsgBox "Next button clicked."
Case 4
MsgBox "Back button clicked."
Case 5
MsgBox "Okay button clicked."
Case 6
MsgBox "Close button clicked."
swTaskPane.DeleteView
End Select
End Function