- UID
- 33426
- 积分
- 0
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2003-3-5
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2004-9-9 16:24:11
|
显示全部楼层
- [FONT=courier new]
- Option Explicit
- '
- '**abCAD Setup**
- '
- 'COPY文件并在AutoCAD中新建工具栏图标
- '
- 'author: abt(ze_zh@sina.com:意见、建议)
- 'date: 2004-7-25/7-27
- '****
- '
- Const AppName As String = "abCAD"
- Const AppMacroName As String = AppName
- Const AppMacro As String = "abCAD/abCAD.dvb!ThisDrawing.Main"
- Const AppBitmaps As String = AppName & ".bmp"
- Const AppToolBarTag As String = "ID_TbStandar"
- Const PathSep As String * 1 = ""
- Const CADVerMin As Integer = 15
- Private acadApp As Object
- Private fs As Object
- Private mbCloseAcad As Boolean '是否关闲Acad
- Public Sub Main()
- Dim r As String
-
- On Error Resume Next
-
- If Not getAcad() Then r = "无可用AutoCAD": GoTo L
- If Not chkVer(acadApp.Version) Then r = "不支持的AutoCAD版本": GoTo L
-
- Set fs = CreateObject("Scripting.FileSystemObject")
-
- copyFiles fs.GetFolder(App.path), acadApp.path & PathSep
- If Not createAppButton() Then r = "未能生成AutoCAD工具栏图标"
-
- L: If mbCloseAcad Then acadApp.Quit
-
- If r <> "" Then r = AppName & "安装失败:" & r Else r = AppName & "成功安装!" & vbCrLf & "欢迎使用!" & vbCrLf & "查看帮助请点击AutoCAD标准工具栏中<ab>图标"
- showInfo r
- End Sub
- 'get AutoCAD app
- Private Function getAcad() As Boolean
- Dim i As Integer
-
- On Error Resume Next
-
- mbCloseAcad = False
- Do
- Set acadApp = GetObject(, "AutoCAD.Application")
- If Err = 0 Then
- getAcad = True: Exit Function
- End If
-
- Err.Clear
- i = MsgBox("当前没有正在运行的AutoCAD." & vbCrLf & "强烈建议安装" & AppName & "之前,先打开AutoCAD!", vbAbortRetryIgnore + vbExclamation)
- If i = vbAbort Then getAcad = False: Exit Function
- Loop While i = vbRetry
-
- Set acadApp = CreateObject("AutoCAD.Application")
- If Err <> 0 Then getAcad = False: Exit Function
- acadApp.Visible = False
-
- mbCloseAcad = True
- getAcad = True
- End Function
- 'chk version
- Private Function chkVer(sVer As String) As Boolean
- Dim i As Integer
- Dim s As String
-
- chkVer = False
-
- i = InStr(sVer, ".")
- If i <= 1 Then Exit Function
- s = Left(sVer, i - 1)
- If Not IsNumeric(s) Then Exit Function
-
- chkVer = CInt(s) >= CADVerMin
- End Function
- 'recur to copy files
- Private Sub copyFiles(fo As Object, pathDest As String)
- Dim foSub As Object
- Dim path As String
-
- On Error Resume Next
-
- For Each foSub In fo.SubFolders
- path = pathDest & foSub.Name & PathSep
- If Not fs.FolderExists(path) Then fs.CreateFolder path
- fs.CopyFile foSub.path & PathSep & "*.*", path, True
- If Err <> 0 Then Err.Clear
-
- copyFiles foSub, path
- Next
- End Sub
- 'show info
- Private Sub showInfo(sInfo As String)
- MsgBox sInfo, vbInformation
- End Sub
- [B]'主要是这个函数[/B]
- 'creat tool bar button
- Private Function createAppButton() As Boolean
- Dim menuGroup As Object
- Dim toolBar As Object
- Dim button As Object
- Dim doc As Object
-
- Dim sMacro As String
- Dim b As Boolean
-
- On Error Resume Next
-
- createAppButton = False
-
- 'save doc
- For Each doc In acadApp.Documents
- If Not doc.Saved Then doc.Save
- Next
-
- Set menuGroup = acadApp.MenuGroups("ACAD")
- If Err <> 0 Then Exit Function
-
- b = False
- For Each toolBar In menuGroup.Toolbars
- If StrComp(toolBar.TagString, AppToolBarTag, vbTextCompare) = 0 Then b = True: Exit For
- Next
- If Not b Then Exit Function
-
- If Not toolBar.Visible Then toolBar.Visible = True
- Set button = toolBar.Item(toolBar.Count - 1)
-
- sMacro = Chr(3) & Chr(3) & Chr(95) & "-VBARUN " & AppMacro & Chr(32)
- 'b = True
- If button.Type = 0 Then 'acToolbarButton
- If StrComp(Left(button.Name, Len(AppMacroName)), AppMacroName, vbTextCompare) = 0 Then
- button.Macro = sMacro
- menuGroup.Save 1 'acMenuFileSource
-
- createAppButton = Err = 0
- Exit Function
- End If
- End If
-
- Set button = toolBar.AddToolbarButton(toolBar.Count, AppMacroName, AppMacroName, sMacro)
- toolBar.AddSeparator toolBar.Count
- [B]'下面这条语句引用CAD2004退出[/B]
- button.SetBitmaps AppBitmaps, AppBitmaps
- menuGroup.Save 1 'acMenuFileSource
-
- createAppButton = Err = 0
- End Function
- [/FONT]
一个很小的安装程序,用的VB6,COPY文件再在CAD中创建工具栏按钮,在R2002下无错,R2004下设置图标时错误并退出。请看看最后一个函数。
多谢斑竹!!! |
|