⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 application.cls

📁 SolidWorks二次开发实例,插件生成模板源码
💻 CLS
字号:
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "Application"
Attribute VB_GlobalNameSpace = True
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
'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

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Implementation methods of the SwAddin interface
Private Function SwAddin_ConnectToSW(ByVal ThisSW As Object, ByVal Cookie As Long) As Boolean
    ' need to add "Microsoft Scripting Runtime"
    Dim fso                 As New Scripting.FileSystemObject
    
    Dim pictNone            As Picture
    Dim pictPart            As Picture
    Dim pictAssy            As Picture
    Dim pictDraw            As Picture
    
    Dim fileNone            As String
    Dim filePart            As String
    Dim fileAssy            As String
    Dim fileDraw            As String
    
    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)
    
    ' extract bitmaps from resources
    Set pictNone = LoadResPicture(101, vbResBitmap)
    Set pictPart = LoadResPicture(102, vbResBitmap)
    Set pictAssy = LoadResPicture(103, vbResBitmap)
    Set pictDraw = LoadResPicture(104, vbResBitmap)
    
    ' get temp filenames for bitmaps
    fileNone = fso.GetTempName
    filePart = fso.GetTempName
    fileAssy = fso.GetTempName
    fileDraw = fso.GetTempName
    
    ' save bitmaps to disk
    SavePicture pictNone, fileNone
    SavePicture pictPart, filePart
    SavePicture pictAssy, fileAssy
    SavePicture pictDraw, fileDraw
    
    bRet = iSldWorks.AddMenuItem3(swDocNONE, iCookie, "DocNONE_Item@Sample", -1, "DocNONE_Item", "DocNONE_ItemUpdate", "Sample|DocNONE_Item hint string", fileNone)
    
    bRet = iSldWorks.AddMenuItem3(swDocPART, iCookie, "DocPART_Item@Sample", -1, "DocPART_Item", "DocPART_ItemUpdate", "Sample|DocPART_Item hint string", filePart)
    bRet = iSldWorks.AddMenuItem3(swDocASSEMBLY, iCookie, "DocASSEMBLY_Item@Sample", -1, "DocASSEMBLY_Item", "DocASSEMBLY_ItemUpdate", "Sample|DocASSEMBLY_Item hint string", fileAssy)
    bRet = iSldWorks.AddMenuItem3(swDocDRAWING, iCookie, "DocDRAWING_Item@Sample", -1, "DocDRAWING_Item", "DocDRAWING_ItemUpdate", "Sample|DocDRAWING_Item hint string", fileDraw)
    
    ' remove temporary bitmap files
    fso.DeleteFile fileNone, True
    fso.DeleteFile filePart, True
    fso.DeleteFile fileAssy, True
    fso.DeleteFile fileDraw, True

    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", "")
    
    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

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -