cqy发表于2005-4-1 14:09:00比如:100-DN50,50-DN50.....等分布在图面上,统计100+50+...
实现这个很简单,把楼主的程序稍作修改就可以了。 可用于单行文字和多行文字。 根据需要自行修改过滤条件。 '数字求和 Sub totalnumber() Dim total As Double total = 0 Dim ssetObj As AcadSelectionSet Set ssetObj = CreateSelectionSet("numberobj") Dim fType, fData BuildFilter fType, fData, 0, "*text", 1, "*DN50" ssetObj.SelectOnScreen fType, fData For i = 0 To ssetObj.Count - 1 total = total + Val(ssetObj(i).TextString) Next ssetObj.Delete ActiveDocument.Utility.Prompt "总和=" & total End Sub Public Function CreateSelectionSet(Optional ssName As String = "ss") As AcadSelectionSet '返回一个空白选择集 Dim ss As AcadSelectionSet On Error Resume Next Set ss = ThisDrawing.SelectionSets(ssName) If Err Then Set ss = ThisDrawing.SelectionSets.Add(ssName) ss.Clear Set CreateSelectionSet = ss End Function Public Sub BuildFilter(typeArray, dataArray, ParamArray gCodes()) '用数组方式填充一对变量以用作为选择集过滤器使用 Dim fType() As Integer, fData() Dim Index As Long, i As Long Index = LBound(gCodes) - 1 For i = LBound(gCodes) To UBound(gCodes) Step 2 Index = Index + 1 ReDim Preserve fType(0 To Index) ReDim Preserve fData(0 To Index) fType(Index) = CInt(gCodes(i)) fData(Index) = gCodes(i + 1) Next typeArray = fType: dataArray = fData End Sub |