我们知道 对象的长度可以用 object.length 获得,但是对于多段线,只能获得合计的长度,如何显示每段的长度呢。这是我的小程序,希望对大家有帮助。
Function PLinelength(ent As AcadEntity) As String On Error GoTo errHandle Dim i As Integer Dim myPointSta As Variant, myPointEnd As Variant Dim myLength As Double
i = 1 myPointSta = ent.Coordinate(0)
Do myPointEnd = ent.Coordinate(i) myLength = VBA.Sqr((myPointSta(0) - myPointEnd(0)) ^ 2 + (myPointSta(1) - myPointEnd(1)) ^ 2)
myPointSta = myPointEnd PLinelength = IIf(PLinelength = "", myLength, PLinelength & "+" & myLength) i = i + 1 Loop Until Err
errHandle:
End Function
Sub 测试程序()
'//////////////////////////////////////////////// Dim ssetObj As AcadSelectionSet Dim tCONUT As Integer tCONUT = 0 tCONUT = ThisDrawing.SelectionSets.Count For ti = 0 To tCONUT - 1 '删除所有的选择集 Set ssetObj = ThisDrawing.SelectionSets.Item(0) ssetObj.Delete Next ti
'////////////////////////////////////////////////// Set sel = ThisDrawing.SelectionSets.Add("ssel")
If Err Then Err.Clear Set sel = ThisDrawing.SelectionSets.Item("ssel")
End If
Lab_star:
sel.SelectOnScreen
Dim ent As AcadEntity
For Each ent In sel
MsgBox PLinelength(ent) Next ent
End Sub
|