创建射线后,可以使用 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 Double
newVector(0) = -1
newVector(1) = 1
newVector(2) = 0
rayObj.DirectionVector = newVector
ThisDrawing.Regen False
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"
End Sub