本例使用两点 (5, 0, 0) 和 (1, 1, 0) 创建一个 Ray 对象。然后查询当前的基点和方向矢量,并将结果显示在消息框中。最后更改方向矢量,并再次查询和显示基点及新的方向矢量。
Sub 通过两点画射线()
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 "射线基点是: " & rayObj.basePoint(0) & _
", " & rayObj.basePoint(1) & _
", " & rayObj.basePoint(2) & _
vbCrLf & "射线的方向矢量是: " & _
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 "射线基点是: " & rayObj.basePoint(0) & _
", " & rayObj.basePoint(1) & _
", " & rayObj.basePoint(2) & _
vbCrLf & "射线的方向矢量是: " & _
rayObj.DirectionVector(0) & ", " & _
rayObj.DirectionVector(1) & ", " & _
rayObj.DirectionVector(2), , "Edit Ray"
End Sub