- 积分
- 898
- 明经币
- 个
- 注册时间
- 2004-10-27
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2004-12-6 23:03:00
|
显示全部楼层
试了一下,sendcommand是容易引起程序运行混乱,不知道vlax是不是可以解决这个问题?以下一个程序是我以前编写的,用于统计某个目录下的所有图纸信息的,贴出来供citykunan参考。- Private Type BrowseInfo
- hWndOwner As Long
- pIDLRoot As Long
- pszDisplayName As Long
- lpszTitle As Long
- ulFlags As Long
- lpfnCallback As Long
- lParam As Long
- iImage As Long
- End TypePrivate Const BIF_RETURNONLYFSDIRS = 1
- Private Const MAX_PATH = 260
- 'Public Declare Function GetVersion Lib "Kernel32" () As Integer
- Private Declare Function GetCommandLine Lib "Kernel32" Alias "GetCommandLineA" () As String
- Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)
- Private Declare Function lstrcat Lib "Kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
- Private Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As Long
- Private Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As LongPublic Sub qdtubl()
- Dim inDir As String
- Dim elem
- Dim filenom As String
- Dim WholeFile As String
- Dim newHeight As Double
- Dim intfilename As Integer
- Dim extmin1 As Double
- Dim extmax1 As Double
- Dim extmin2 As Double
- Dim extmax2 As Double
- Dim scale1 As Double
- Dim tufu As String
- Dim neirong33 As String
- intfilename = FreeFile()
- inDir = ""
- inDir = ThisDrawing.BrowseForFolder("请选择目录:")
- If inDir = "" Then Exit Sub
- If Right(inDir, 1) = "" Then inDir = Left(inDir, Len(inDir) - 1)
- filenom = Dir$(inDir & "\*.dwg")
- Dim tzlbzz As String
- tzlbzz = inDir & "\图纸幅面及比例.txt"'On Error GoTo errorcontrol
- Open tzlbzz For Output As intfilename
- Print #intfilename, inDir
- Print #intfilename, "---------------"
- Do While filenom <> ""
-
- WholeFile = inDir & "" & filenom
- ThisDrawing.Application.Documents.Open WholeFile
- extmin1 = ThisDrawing.Application.ActiveDocument.GetVariable("extmax")(0) - ThisDrawing.Application.ActiveDocument.GetVariable("extmin")(0)
- extmax1 = ThisDrawing.Application.ActiveDocument.GetVariable("extmax")(1) - ThisDrawing.Application.ActiveDocument.GetVariable("extmin")(1)
- scale1 = ThisDrawing.Application.ActiveDocument.GetVariable("dimscale")
- If scale1 = 0 Then scale1 = 1
- extmin2 = extmin1 / scale1
- extmax2 = extmax1 / scale1
- If extmin2 > extmax2 Then
- Select Case ThisDrawing.Round(extmin2, 0)
- Case 1189
- tufu = "图幅A0"
- Case 841
- tufu = "图幅A1"
- Case 594
- tufu = "图幅A2"
- Case 420
- tufu = "图幅A3"
- Case 297
- tufu = "图幅A4"
- Case Else
- tufu = "图幅未知"
- End Select
- Else
- Select Case ThisDrawing.Round(extmin2, 0)
- Case 841
- tufu = "图幅A0"
- Case 594
- tufu = "图幅A1"
- Case 420
- tufu = "图幅A2"
- Case 297
- tufu = "图幅A3"
- Case 210
- tufu = "图幅A4"
- Case Else
- tufu = "图幅未知"
- End Select
- End If
- neirong33 = filenom & Chr(9) & tufu & "(" & CStr(extmin2) & "," & CStr(extmax2) & ")" & Chr(9) & "比例(1:" & CStr(scale1) & ")"
- Print #intfilename, neirong33
- 'MsgBox ThisDrawing.GetVariable("extmax")
- ThisDrawing.Application.ActiveDocument.Close False
- filenom = Dir$
- ThisDrawing.Utility.Prompt vbCrLf
- Loop
- Close intfilename
- 'MsgBox tzlbzz
- Dim runtemp As String
- runtemp = "NOTEPAD.EXE " & tzlbzz
- Shell runtemp, vbNormalFocus
- Exit Suberrorcontrol:
- Close intfilename
- MsgBox "错误,程序退出!"
- End SubPublic Function Round(ByVal nValue, Optional nPlaces As Integer = 2) As Double Dim tmp As Integer
- On Error GoTo errorcontrol
-
- nValue = CDbl(nValue)
- tmp = Fix(nValue)
- nValue = CInt((nValue - tmp) * 10 ^ nPlaces)
- Round = tmp + nValue / 10 ^ nPlaces
- Exit Function
-
- errorcontrol:
- Round = 0
- End FunctionPublic Function BrowseForFolder(sPrompt As String) As String
- 'Public Function BrowseForFolder(hWndOwner As Long, sPrompt As String) As StringDim iNull As Integer
- Dim lpIDList As Long
- Dim lResult As Long
- Dim sPath As String
- Dim udtBI As BrowseInfo
- With udtBI
- ' .hWndOwner = hWndOwner
- .lpszTitle = lstrcat(sPrompt, "")
- .ulFlags = BIF_RETURNONLYFSDIRS
- End With lpIDList = SHBrowseForFolder(udtBI) If lpIDList Then
- sPath = String$(MAX_PATH, 0)
- lResult = SHGetPathFromIDList(lpIDList, sPath)
- Call CoTaskMemFree(lpIDList)
- iNull = InStr(sPath, vbNullChar) If iNull Then
- sPath = Left$(sPath, iNull - 1)
- End If End If BrowseForFolder = sPath
- End Function
|
|