- Sub test()
- Dim selobj As AcadEntity
- Dim pPt As Variant
-
- On Error GoTo ErrTrap
- '选择多段线
- ThisDrawing.Utility.GetEntity selobj, pPt, "指定多段线: "
- If selobj.EntityName = "AcDbPolyline" Then
- Dim explodedObjects As Variant
- '炸开
- explodedObjects = selobj.Explode
- Dim i As Integer
- Dim sPt As Variant
- Dim ePt As Variant
- Dim EntObj As AcadEntity
- For i = 0 To UBound(explodedObjects)
- sPt = explodedObjects(i).StartPoint
- ePt = explodedObjects(i).EndPoint
- '判断选择点是否位于直线两端点的X坐标和Y坐标之内
- '一般情况下这种方法是可行的,对于特殊情况未做判断
- If (pPt(0) > sPt(0) And pPt(0) < ePt(0)) Or (pPt(0) > ePt(0) And pPt(0) < sPt(0)) Then
- If (pPt(0) > sPt(0) And pPt(0) < ePt(0)) Or (pPt(0) > ePt(0) And pPt(0) < sPt(0)) Then
- Set EntObj = explodedObjects(i)
- Exit For
- End If
- End If
- Next
- If Not (EntObj Is Nothing) Then
- Debug.Print "距选择点最近的直线: " & EntObj.Handle
- End If
- End If
- Exit Sub
-
- ErrTrap:
- If ThisDrawing.GetVariable("errno") = 7 Then
- Resume
- End If
- On Error GoTo 0
- End Sub
|