贴出我的源程序
Sub Count_len()
' 创建新的选择集
Dim sset As AcadSelectionSet
For i = 0 To ThisDrawing.SelectionSets.Count - 1
ThisDrawing.SelectionSets.Item(i).Clear
ThisDrawing.SelectionSets.Item(i).Delete
Next
On Error Resume Next
Set sset = ThisDrawing.SelectionSets.Add("SS0")
sset.SelectOnScreen
Dim entry As AcadEntity
Dim l_text As String
Dim l_l As Double
Dim Arc_count As Integer
Dim Line_count As Integer
For Each entry In sset
'如果是多段线或曲线的长度,就不行了
If entry.ObjectName = "AcDbArc" Then
l_text = l_text & "+" & entry.ArcLength
l_l = l_l + entry.ArcLength
Arc_count = Arc_count + 1
ElseIf entry.ObjectName = "AcDbLine" Then
l_text = l_text & "+" & entry.Length
l_l = l_l + entry.Length
Line_count = Line_count + 1
End If
Next entry
Public Sub Test() Dim objAcadObject As AcadObject Dim varPickedPoint As Variant Dim objDocument As AcadDocument ThisDrawing.Utility.GetEntity objAcadObject, varPickedPoint, "請選擇 Polyline" If TypeOf objAcadObject Is AcadPolyline Then Dim objPolyline As AcadPolyline Set objPolyline = objAcadObject MsgBox "Polyline 長度=" + CStr(objPolyline.Length) End If End Sub