可使用vlax 类和curve类模块来解决:
- Sub GetClosestPoint()
- 'ThisDrawing.SendCommand "(vl-load-com)" & vbCrLf
- '定义引用曲线类模块
- Dim ObjCurve As Curve
- Set ObjCurve = New Curve
- '获取曲线
- Dim Pnt As Variant
- Dim Ent As AcadEntity
- ThisDrawing.Utility.GetEntity Ent, Pnt, "选择曲线:"
- '亮显刚选定的曲线以方便捕捉曲线上的点
- Ent.Highlight True
- '捕捉曲线上的一个点
- Pnt = ThisDrawing.Utility.GetPoint(, "选择曲线外的一点:")
- '通过曲线类模块获取曲线距离选取点最近的点
- Set ObjCurve.Entity = Ent
- Dim ClosestPnt As Variant
- ClosestPnt = ObjCurve.GetClosestPointTo(Pnt)
- '显示曲线长度
- MsgBox "曲线上距离选取点最近的点坐标为:" & vbCrLf & vbCrLf & ClosestPnt(0) & "," & ClosestPnt(1) & "," & ClosestPnt(2), , "明经通道VBA示例"
- '取消曲线的亮显
- Ent.Highlight False
- '释放变量
- Set ObjCurve = Nothing
- End Sub
|