'-------------------------------------
' SW Addin by VB
'-------------------------------------
Const swdocnone = 0
Const swDocPART = 1
Const swDocASSEMBLY = 2
Const swDocDRAWING = 3
Const swDocTemplateTypeNONE = &H1
Const swDocTemplateTypePART = &H2
Const swDocTemplateTypeASSEMBLY = &H4
Const swDocTemplateTypeDRAWING = &H8
'Make sure that a reference to the swpublished.tlb type library exists确保swpublished.tlb被引用
'Tell VB that you are going to provide functionality for the SwAddin interface告诉VB你要继续为插件提供功能
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
' MsgBox "SwAddin_ConnectToSW"
' store reference to SW session ,存引用到SW session
Set iSldWorks = ThisSW
' store cookie from SW,从SW存cookie
iCookie = Cookie
'Inform SW about the object that contains the callbacks,含有callbacks的对象信息
bRet = iSldWorks.SetAddinCallbackInfo(App.hInstance, Me, iCookie)
'Add a menu item on the frame when no documents are present
'bRet = iSldWorks.AddMenu(swdocnone, "毛坯转换CAD", 3) '加菜单
'bRet = iSldWorks.AddMenu(swDocPART, "毛坯转换CAD", 3) '加菜单
bRet = iSldWorks.AddMenu(swDocPART, "毛坯转换CAD", 5) '加菜单
'bRet = iSldWorks.AddMenu(swDocDRAWING, "毛坯转换CAD", 3) '加菜单
'加菜单项
bRet = iSldWorks.AddMenu(swDocPART, "毛坯转换CAD2", 6)
bRet = iSldWorks.AddMenuItem2(swDocPART, iCookie, "毛坯转换@毛坯转换CAD", -1, "stadard", "stadardUpdate", "毛坯操作")
bRet = iSldWorks.AddMenuItem2(swDocPART, iCookie, "工艺路线@毛坯转换CAD", -1, "gongyi", "gongyiUpdate", "工艺操作")
'bRet = iSldWorks.AddMenuItem2(swdocnone, iCookie, "标准件 1 @毛坯转换CAD", -1, "DocNONE_Item", "DocNONE_ItemUpdate", "标准件 1 操作")
'bRet = iSldWorks.AddMenuItem2(swDocPART, iCookie, "标准件 2 @毛坯转换CAD", -1, "DocPART_Item", "DocPART_ItemUpdate", "标准件 2 操作")
'bRet = iSldWorks.AddMenuItem2(swDocDRAWING, iCookie, "标准件 4 @毛坯转换CAD", -1, "DocDRAWING_Item", "DocDRAWING_ItemUpdate", "标准件 4 操作")
' bRet = iSldWorks.AddMenuItem2(swDocASSEMBLY, iCookie, "标准件@毛坯转换CAD", -1, "stadard", "stadardUpdate", "标准件操作")
' bRet = iSldWorks.AddMenuItem2(swDocASSEMBLY, iCookie, "货叉装置@毛坯转换CAD", -1, "huocha", "huochaUpdate", "货叉装置操作")
' bRet = iSldWorks.AddMenuItem2(swDocASSEMBLY, iCookie, "从动轮@毛坯转换CAD", -1, "tyj1", "tyj1Update", "从动轮操作")
' bRet = iSldWorks.AddMenuItem2(swDocASSEMBLY, iCookie, "导轮组@毛坯转换CAD", -1, "tyj2", "tyj2Update", "导轮组操作")
' bRet = iSldWorks.AddMenuItem2(swDocASSEMBLY, iCookie, "滑轮组@毛坯转换CAD", -1, "tyj3", "tyj3Update", "滑轮组操作")
' bRet = iSldWorks.AddMenuItem2(swDocASSEMBLY, iCookie, "卷筒@毛坯转换CAD", -1, "tyj4", "tyj4Update", "卷筒操作")
' bRet = iSldWorks.AddMenuItem2(swDocASSEMBLY, iCookie, "天轮组@毛坯转换CAD", -1, "tyj5", "tyj5Update", "天轮组操作")
' bRet = iSldWorks.AddMenuItem2(swDocASSEMBLY, iCookie, "载货台@毛坯转换CAD", -1, "tyj6", "tyj6Update", "载货台操作")
' bRet = iSldWorks.AddMenuItem2(swDocASSEMBLY, iCookie, "主动轮@毛坯转换CAD", -1, "tyj7", "tyj7Update", "主动轮操作")
'bRet = iSldWorks.AddMenuItem2(swDocASSEMBLY, iCookie, "通用件8@毛坯转换CAD", -1, "tyj8", "tyj8Update", "通用件8操作")
bRet = iSldWorks.AddMenuItem2(swDocPART, iCookie, "sdsd@退出@毛坯转换CAD", -1, "abort", "abortUpdate", "关于操作")
'建立工具
'iToolbarID = iSldWorks.AddToolbar3(iCookie, "毛坯转换CAD Toolbar", 102, 101, -1, 15) 'swDocTemplateTypeNONE + swDocTemplateTypePART + swDocTemplateTypeASSEMBLY + swDocTemplateTypeDRAWING)
'bRet = iSldWorks.AddToolbarCommand2(iCookie, iToolbarID, 0, "ToolbarFunc", "ToolbarFuncUpdate", "标准件1", "标准件1")
'bRet = iSldWorks.AddToolbarCommand2(iCookie, iToolbarID, 1, "ToolbarFunc", "ToolbarFuncUpdate", "标准件2", "标准件2")
'bRet = iSldWorks.ShowToolbar2(iCookie, iToolbarID)
SwAddin_ConnectToSW = True '连接到SW
End Function
Private Function SwAddin_DisconnectFromSW() As Boolean
'MsgBox "SwAddin_DisconnectFromSW"
Dim bRet As Boolean
'MsgBox ("unload Addin")
'Remove any UI that was added earlier 清除先前加的任何UI
bRet = iSldWorks.RemoveMenu(swdocnone, "毛坯转换CAD", "")
bRet = iSldWorks.RemoveMenu(swDocPART, "毛坯转换CAD", "")
bRet = iSldWorks.RemoveMenu(swDocASSEMBLY, "毛坯转换CAD", "")
bRet = iSldWorks.RemoveMenu(swDocDRAWING, "毛坯转换CAD", "")
'bRet = iSldWorks.RemoveToolbar2(iCookie, iToolbarID)
Set iSldWorks = Nothing
SwAddin_DisconnectFromSW = True '从SW关闭
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Callback routines for SW
Public Sub DocNONE_Item()
MsgBox "毛坯转换CAD|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 DocASSEMBLY_Item()
MsgBox "毛坯转换CAD|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 stadard() '标准件
'定位操作路径及文件
Dim fs, f, s, sss
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(App.Path)
s = f.ParentFolder
sss = s + "\毛坯转换"
'MsgBox Left(sss, 1)
ChDrive sss
ChDir sss
'MsgBox CurDir
'执行操作
Shell sss + "\毛坯.exe"
End Sub
Public Function stadardUpdate() 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
stadardUpdate = 1
End Function
Public Sub gongyi() '标准件
'定位操作路径及文件
Dim fs, f, s, sss
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(App.Path)
s = f.ParentFolder
sss = s + "\工艺路线"
'MsgBox Left(sss, 1)
ChDrive sss
ChDir sss
'MsgBox CurDir
'执行操作
Shell sss + "\工艺路线.exe"
End Sub
Public Function gongyiUpdate() 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
gongyiUpdate = 1
End Function
Public Sub abort() '关于
'MsgBox CurDir
'定位操作路径及文件
Dim fs, f, s, sss
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(App.Path)
s = f.ParentFolder
sss = s + "\退出"
'MsgBox Left(sss, 1)
ChDrive sss
ChDir sss
'MsgBox CurDir
'执行操作
Shell sss + "\tuichu.exe"
End Sub
Public Function abortUpdate() As Long
'Return the state information for the menu item
' 1 - Enabled and unchecked (default when update routine does not exist)
abortUpdate = 1
End Function
Public Sub DocDRAWING_Item()
MsgBox "毛坯转换CAD|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 "ushed"
' 3 Button is Enabled and "ushed
ToolbarFuncUpdate = 1
End Function |