改进后的程序,欢迎下载! 我常用的vba工具中的一小部分
裁出来的,很多定义是其它小程序才用到的
Option Explicit<BR> Dim sysVarName, sysVarNameB As String<BR> Dim varData As Variant<BR> Dim varDataB As Variant<BR> Dim intData As Integer<BR> Dim sysvarData As Variant<BR> Dim sysvarDataB As Variant<BR> Dim varPnt As Variant<BR> Dim sSet, eNt As Object<BR> Dim tText As String<BR> Public Pi As Double<BR>
Public FrNum As Integer<BR> Public textH As Single<BR> <BR> Dim laYerStr(80) As String<BR>Dim laYerColor(80) As Integer<BR> <BR> Public dimS, dimSet, PfSt, MuSt, eveDimset As Integer<BR> '标总面积,标注方式,平方位数,亩位数,逐个标注<BR> Public strExpPf, strExpMu As String<BR> Public strPf, strMu As String<BR> Public BzLay, HxLay As String<BR> Dim Found As Boolean<BR> Dim laYerObj As AcadLayer<BR> Dim NewLayer As AcadLayer<BR>Public FrontText As String<BR>Public FrontNum As Integer<BR>Dim FileName As String<BR>Dim pT1, pT2, pT3, pT4 As Integer<BR>Dim points As Variant<BR>Dim ptMid(0 To 2) As Double '线段中点,文字对齐点<BR>Dim NewPt(0 To 2) As Double<BR>Dim keyWd As String<BR>Dim Ptt As Variant<BR>Dim i, j As Integer
Dim varCancel As Variant<BR> Dim ESC As Long<BR> Public Declare Function CallNextHookEx Lib "user32" _<BR> (ByVal hHook As Long, _<BR> ByVal nCode As Long, _<BR> ByVal wParam As Long, _<BR> ByVal lParam As Long) As Long
Public Declare Function UnhookWindowsHookEx Lib "user32" _<BR> (ByVal hHook As Long) As Long
Public Declare Function SetWindowsHookEx Lib "user32" _<BR> Alias "SetWindowsHookExA" _<BR> (ByVal idHook As Long, _<BR> ByVal lpfn As Long, _<BR> ByVal hmod As Long, _<BR> ByVal dwThreadId As Long) As Long
Public Declare Function PostMessage Lib "user32" _<BR> Alias "PostMessageA" _<BR> (ByVal hwnd As Long, _<BR> ByVal wMsg As Long, _<BR> ByVal wParam As Long, _<BR> ByVal lParam As Long) As Long<BR> Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Const VK_ESCAPE = &H1B
Public Const WH_KEYBOARD = 2<BR>Public Const KBH_MASK = &H20000000<BR>Public Const WM_LBUTTONDOWN = &H201<BR>Public Const WM_LBUTTONUP = &H202
Global hHook As Long<BR>Global EscKey As Boolean
Public Function KeyboardProc(ByVal nCode As Long, ByVal wParam As Long, _<BR> ByVal lParam As Long) As Long<BR> If nCode >= 0 Then<BR> 'Process keys you want to filter<BR> If wParam = 27 Then<BR> EscKey = True<BR> Else<BR> EscKey = False<BR> End If<BR> End If<BR> KeyboardProc = CallNextHookEx(hHook, nCode, wParam, lParam)<BR>End Function<BR>Public Sub hz()<BR> '定义文本值<BR> Dim TextNum As Integer<BR> Dim eveTextNum As Double<BR> Dim MinText As Double<BR> Dim MaxText As Double<BR> Dim AveText As Double<BR> Dim TextHz As Double<BR> '定义实体值<BR> Dim ObjNum As Integer
Dim ObjHz As Double<BR> Dim JudgeClo As Integer<BR> Dim JudgeText As Integer<BR> Dim LongStr As String<BR> Dim eveObjNum As Double<BR> Dim MinObj As Double<BR> Dim MaxObj As Double<BR> Dim AveObj As Double<BR>Dim errCo As Boolean<BR>On Error Resume Next<BR>'*************取得原始文字高*************<BR>'GetOriData<BR>'*************开始程序*************<BR>On Error GoTo Err_Control<BR> <BR>selec:<BR>If ThisDrawing.SelectionSets.Count > 0 Then<BR> For i = 0 To ThisDrawing.SelectionSets.Count - 1<BR> ThisDrawing.SelectionSets.Item(i).Delete<BR> Next i<BR> End If<BR> Set sSet = ThisDrawing.SelectionSets.add("ss1")<BR> sSet.SelectOnScreen<BR>Dim pdText, pdObj As Boolean<BR>pdText = False<BR>pdObj = False
TextNum = 0<BR>TextHz = 0<BR>ObjNum = 0<BR>ObjHz = 0<BR>JudgeClo = 0
For Each eNt In sSet
If eNt.ObjectName = "AcDbText" Or eNt.ObjectName = "AcDbMText" Then<BR> <BR> For i = 1 To Len(eNt.TextString)<BR> If Mid(eNt.TextString, i, 1) = "|" Or Mid(eNt.TextString, i, 1) = "\" Then errCo = True<BR> If Asc(Mid(eNt.TextString, i, 1)) > 47 And Asc(Mid(eNt.TextString, i, 1)) < 58 Then<BR> FrontNum = i - 1<BR> i = Len(eNt.TextString)<BR> End If<BR> Next i<BR> j = 0<BR>For i = 1 To FrontNum<BR>If Mid(eNt.TextString, i, 1) = " " Then j = j + 1<BR>Next i<BR>FrontNum = FrontNum - j
eveTextNum = Val(Right(Trim(eNt.TextString), Len(Trim(eNt.TextString)) - FrontNum))<BR>If errCo = True Then MsgBox "在该文本中发现异常字符,使用该命令后,请检查数据,以免出错!!!" + vbCrLf + " (建议使用Ddmodify命令检查该文本)", vbExclamation, "小游提醒您:"<BR> <BR> TextNum = TextNum + 1<BR> TextHz = TextHz + eveTextNum<BR> <BR> If pdObj = False Then<BR> pdObj = True<BR> MinText = eveTextNum<BR> MaxText = eveTextNum<BR> End If<BR> If eveTextNum < MinText Then MinText = eveTextNum<BR> If eveTextNum > MaxText Then MaxText = eveTextNum<BR> Else<BR> JudgeText = JudgeText + 1<BR> End If
<BR> If eNt.ObjectName = "AcDbPolyline" Or eNt.ObjectName = "AcDbLWPolyline" Then<BR> If eNt.Closed = True Then<BR> If pdText = False Then<BR> pdText = True<BR> MinObj = eNt.Area<BR> MaxObj = eNt.Area<BR> End If<BR> eveObjNum = eNt.Area<BR> ObjNum = ObjNum + 1<BR> ObjHz = ObjHz + eveObjNum<BR> If eveObjNum < MinObj Then MinObj = eveObjNum<BR> If eveObjNum > MaxObj Then MaxObj = eveObjNum<BR> Else<BR> JudgeClo = JudgeClo + 1<BR> End If<BR>End If<BR> Next
If TextNum > 0 Then AveText = TextHz / TextNum<BR>If ObjNum > 0 Then AveObj = ObjHz / ObjNum<BR>LongStr = "文本个数=" & Str(TextNum) & " 实体个数=" & Str(ObjNum) & " 总个数=" & Str(TextNum + ObjNum) & vbCrLf<BR>ThisDrawing.Utility.Prompt LongStr<BR>LongStr = " 最小文本=" & Str(Trim(Format(MinText, "0.000"))) & " 最小实体=" & Str(Trim(Format(MinObj, "0.000"))) & vbCrLf<BR>ThisDrawing.Utility.Prompt LongStr<BR>LongStr = " 最大文本=" & Str(Trim(Format(MaxText, "0.000"))) & " 最大实体=" & Str(Trim(Format(MaxObj, "0.000"))) & vbCrLf<BR>ThisDrawing.Utility.Prompt LongStr<BR>LongStr = " 平均文本值=" & Str(Trim(Format(AveText, "0.000"))) & " 平均实体值=" & Str(Trim(Format(AveObj, "0.000"))) & vbCrLf<BR>ThisDrawing.Utility.Prompt LongStr<BR>LongStr = "总文本值=" & Str(Trim(Format(TextHz, "0.000"))) & " 总实体值=" & Str(Trim(Format(ObjHz, "0.000"))) & " 两项总值=" & Str(Trim(Format(TextHz + ObjHz, "0.000"))) & vbCrLf<BR>ThisDrawing.Utility.Prompt LongStr<BR>If JudgeText <> 0 Then<BR>'LongStr = "另有" & Str(JudgeText) & "个文本设置的现有数值前字符数大于整个文本长,未进行统计" & vbCrLf<BR>ThisDrawing.Utility.Prompt LongStr<BR>End If
If JudgeClo <> 0 Then<BR>LongStr = "另有" & Str(JudgeClo) & "条多义线未闭合,未进行面积统计,请处理以免出错" & vbCrLf<BR>ThisDrawing.Utility.Prompt LongStr<BR>End If
En:<BR>Exit_Here:<BR> Call UnhookWindowsHookEx(hHook)<BR> Exit Sub<BR>Err_Control:<BR> varCancel = ThisDrawing.GetVariable("LASTPROMPT")<BR> ESC = GetAsyncKeyState(VK_ESCAPE)<BR> Select Case Err.Number<BR> '按了取消键或其它透明命令<BR> Case -2147352567<BR> '如果命令行提示中没有“取消”这样的文字出现<BR> '一般来说在2002中按了回车或空格都不会出现“取消”<BR> '则退出<BR> If InStr(1, varCancel, "*Cancel*") <> 0 And _<BR> InStr(1, varCancel, "*取消*") <> 0 Then<BR> Err.Clear<BR> Resume Exit_Here<BR> '如果按了“取消”键,则退出<BR> ElseIf ESC <> 0 Then<BR> Err.Clear<BR> Resume Exit_Here<BR> '其它情况下,则恢复。如选择了透明命令,则会出现“取消”<BR> '字样,但不是按了“取消”键。<BR> Else<BR> Err.Clear<BR> Resume<BR> End If<BR> '右键单击或回车或空格。<BR> '在这里,-2147467259用于AutoCAD 2000 及2002,<BR> '而-2145320928为2004专用<BR> Case -2147467259, -2145320928<BR> Err.Clear<BR> Resume Exit_Here<BR> '其它情况,一律退出<BR> Case Else<BR> Err.Clear<BR> Resume Exit_Here<BR> End Select
<BR>End Sub
页:
1
[2]