About Querying Rays (VBA/ActiveX)

Once created, you can query a ray to determine the points used to create the object.

The BasePoint property can be used to obtain the first point of the ray. While the second point used to create the ray is not stored with the object, you can use the DirectionVector property to obtain the directional vector for the ray.

Add, query, and edit a Ray object

The following example code creates a Ray object using the two points (5, 0, 0) and (1, 1, 0). It then queries the current base point and direction vector and displays the results in a message box. The direction vector is then changed and the base point and new direction vector are queried and displayed.

Sub Ch3_EditRay()
  Dim rayObj As AcadRay
  Dim basePoint(0 To 2) As Double
  Dim secondPoint(0 To 2) As Double

  ' Define the ray
  basePoint(0) = 3#: basePoint(1) = 3#: basePoint(2) = 0#
  secondPoint(0) = 4#: secondPoint(1) = 4#: secondPoint(2) = 0#

  ' Creates a Ray object in model space
  Set rayObj = ThisDrawing.ModelSpace.AddRay(basePoint, secondPoint)
  ThisDrawing.Application.ZoomAll

  ' Find the current status of the 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"

  ' Change the directional vector for the 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