查询射线
From AutoCAD ActiveX/VBA
创建射线后,可以使用 BasePoint 特性查询射线的第一个点。用于创建射线的第二个点并未存储在对象中,而使用 DirectionVector 特性来获取射线的方向矢量。
下面的代码样例使用两点 (5, 0, 0) 和 (1, 1, 0) 创建一个 Ray 对象。然后查询当前的基点和方向矢量,并将结果显示在消息框中。最后更改方向矢量,并再次查询和显示基点及新的方向矢量。
Sub Ch3_EditRay()
Dim rayObj As AcadRay
Dim basePoint(0 To 2) As Double
Dim secondPoint(0 To 2) As Double
' 定义射线basePoint(0) = 3#: basePoint(1) = 3#: basePoint(2) = 0#secondPoint(0) = 4#: secondPoint(1) = 4#: secondPoint(2) = 0#' 在模型空间中创建 Ray 对象Set rayObj = ThisDrawing.ModelSpace.AddRay _(basePoint, secondPoint)ThisDrawing.Application.ZoomAll' 查找 Ray 的当前状态MsgBox "The base point of the ray is: " & _rayObj.basePoint(0) & ", " & _rayObj.basePoint(1) & ", " & _rayObj.basePoint(2) & vbCrLf & _"The directional vector for the ray is: " & _rayObj.DirectionVector(0) & ", " & _rayObj.DirectionVector(1) & ", " & _rayObj.DirectionVector(2), , "Edit Ray"' 更改射线的方向矢量Dim newVector(0 To 2) As DoublenewVector(0) = -1newVector(1) = 1newVector(2) = 0rayObj.DirectionVector = newVectorThisDrawing.Regen FalseMsgBox "The base point of the ray is: " & _rayObj.basePoint(0) & ", " & _rayObj.basePoint(1) & ", " & _rayObj.basePoint(2) & vbCrLf & _"The directional vector for the ray is: " & _rayObj.DirectionVector(0) & ", " & _rayObj.DirectionVector(1) & ", " & _rayObj.DirectionVector(2), , "Edit Ray"End Sub