How using an implements class in my VB6 project please ?
Here is my main() module :
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Debug.Print "coucou"
Shell ("C:\Program Files\SolidWorks\SLDWORKS.exe")
' After refer all references
' Attach to running instance of SolidWorks software
Set swApp = GetObject(, "SldWorks.Application")
Set swModel = swApp.ActiveDoc
' How Can I use here the swaddin class : "SwAddin.cls"?
' Closing
swApp.ExitApp
callback1
End Sub
A function :
Sub callback1()
Debug.Print "ben alors"
End Sub
Here is the implements class, "SwAddin.cls" that I don't know how using
'Make sure that a reference to the swpublished.tlb type library exists
'Tell VB that you are going to provide functionality for the SwAddin interface
Implements SWPublished.SWAddin
Dim iSldWorks As SldWorks.SldWorks
Dim iCookie As Long
Dim iToolbarID As Long
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Implementation methods of the SwAddin interface
Private Function SwAddin_ConnectToSW(ByVal ThisSW As Object, ByVal Cookie As Long) As Boolean
Dim bRet As Boolean
' store reference to SW session
Set iSldWorks = ThisSW
' store cookie from SW
iCookie = Cookie
'Inform SW about the object that contains the callbacks
bRet = iSldWorks.SetAddinCallbackInfo(App.hInstance, Me, iCookie)
'Add a menu item on the frame when no documents are present
bRet = iSldWorks.AddMenu(swDocNONE, "Sample", 3)
bRet = iSldWorks.AddMenuItem2(swDocNONE, iCookie, "DocNONE_Item@Sample", -1, "DocNONE_Item", "DocNONE_ItemUpdate", "Sample|DocNONE_Item hint string")
bRet = iSldWorks.AddMenuItem2(swDocPART, iCookie, "DocPART_Item@Sample", -1, "DocPART_Item", "DocPART_ItemUpdate", "Sample|DocPART_Item hint string")
bRet = iSldWorks.AddMenuItem2(swDocASSEMBLY, iCookie, "DocASSEMBLY_Item@Sample", -1, "DocASSEMBLY_Item", "DocASSEMBLY_ItemUpdate", "Sample|DocASSEMBLY_Item hint string")
bRet = iSldWorks.AddMenuItem2(swDocDRAWING, iCookie, "DocDRAWING_Item@Sample", -1, "DocDRAWING_Item", "DocDRAWING_ItemUpdate", "Sample|DocDRAWING_Item hint string")
iToolbarID = iSldWorks.AddToolbar3(iCookie, "Sample Toolbar", 102, 101, -1, _
swDocTemplateTypeNONE + swDocTemplateTypePART + swDocTemplateTypeASSEMBLY + swDocTemplateTypeDRAWING)
bRet = iSldWorks.AddToolbarCommand2(iCookie, iToolbarID, 0, "ToolbarFunc", "ToolbarFuncUpdate", "Press Me!", "Hint in status bar")
' DO NOT use - toolbar visibility managed by SW
'bRet = iSldWorks.ShowToolbar2(iCookie, iToolbarID)
SwAddin_ConnectToSW = True
End Function
Private Function SwAddin_DisconnectFromSW() As Boolean
Dim bRet As Boolean
'Remove any UI that was added earlier
bRet = iSldWorks.RemoveMenu(swDocNONE, "Sample", "")
bRet = iSldWorks.RemoveMenu(swDocPART, "Sample", "")
bRet = iSldWorks.RemoveMenu(swDocASSEMBLY, "Sample", "")
bRet = iSldWorks.RemoveMenu(swDocDRAWING, "Sample", "")
bRet = iSldWorks.RemoveToolbar2(iCookie, iToolbarID)
Set iSldWorks = Nothing
SwAddin_DisconnectFromSW = True
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Callback routines for SW
Public Sub DocNONE_Item()
MsgBox "Sample|DocNONE_Item menuitem was called"
End Sub
Public Function DocNONE_ItemUpdate() As Long
'Return the state information for the menu item
' 0 - Disabled and unchecked
' 1 - Enabled and unchecked (default when update routine does not exist)
' 2 - Disabled and checked
' 3 - Enabled and checked
DocNONE_ItemUpdate = 1
End Function
Public Sub DocPART_Item()
MsgBox "Sample|DocPART_Item menuitem was called"
End Sub
Public Function DocPART_ItemUpdate() As Long
'Return the state information for the menu item
' 0 - Disabled and unchecked
' 1 - Enabled and unchecked (default when update routine does not exist)
' 2 - Disabled and checked
' 3 - Enabled and checked
DocPART_ItemUpdate = 1
End Function
Public Sub DocASSEMBLY_Item()
MsgBox "Sample|DocASSEMBLY_Item menuitem was called"
End Sub
Public Function DocASSEMBLY_ItemUpdate() As Long
'Return the state information for the menu item
' 0 - Disabled and unchecked
' 1 - Enabled and unchecked (default when update routine does not exist)
' 2 - Disabled and checked
' 3 - Enabled and checked
DocASSEMBLY_ItemUpdate = 1
End Function
Public Sub DocDRAWING_Item()
MsgBox "Sample|DocDRAWING_Item menuitem was called"
End Sub
Public Function DocDRAWING_ItemUpdate() As Long
'Return the state information for the menu item
' 0 - Disabled and unchecked
' 1 - Enabled and unchecked (default when update routine does not exist)
' 2 - Disabled and checked
' 3 - Enabled and checked
DocDRAWING_ItemUpdate = 1
End Function
Public Sub ToolbarFunc()
MsgBox "Toolbar function was called"
End Sub
Public Function ToolbarFuncUpdate() As Long
' 0 Button is disabled (grey)
' 1 Button is enabled. This is the default state with if no update function is specified.
' 2 Button is Disabled and "Pushed"
' 3 Button is Enabled and "Pushed
ToolbarFuncUpdate = 1
End Function