Specify 3D Coordinates
 
 
 

Entering 3D world coordinate system (WCS) coordinates is similar to entering 2D WCS coordinates. In addition to specifying X and Y values, you specify a Z value. As with the 2D coordinates, a variant is used to pass the coordinates to ActiveX. methods and properties, and to query the coordinates.

For more information about specifying 3D coordinates, see “Enter 3D Coordinates” in the User's Guide.

Define and query the coordinates for 2D and 3D polylines

This example creates two polylines, each with three coordinates. The first polyline is a 2D polyline, the second polyline is 3D. Notice that the length of the array containing the vertices is expanded to include the Z coordinates in the creation of the 3D polyline. The example concludes by querying the coordinates of the polylines and displaying the coordinates in a message box.

Sub Ch8_Polyline_2D_3D()
	Dim pline2DObj As AcadLWPolyline
	Dim pline3DObj As AcadPolyline


	Dim points2D(0 To 5) As Double
	Dim points3D(0 To 8) As Double


	' Define three 2D polyline points
   points2D(0) = 1: points2D(1) = 1
   points2D(2) = 1: points2D(3) = 2
   points2D(4) = 2: points2D(5) = 2


	' Define three 3D polyline points
   points3D(0) = 1: points3D(1) = 1: points3D(2) = 0
   points3D(3) = 2: points3D(4) = 1: points3D(5) = 0
   points3D(6) = 2: points3D(7) = 2: points3D(8) = 0


	' Create the 2D light weight Polyline
	Set pline2DObj = ThisDrawing.ModelSpace. _
							 AddLightWeightPolyline(points2D)
	pline2DObj.Color = acRed
	pline2DObj.Update


	' Create the 3D polyline
	Set pline3DObj = ThisDrawing.ModelSpace. _
							 AddPolyline(points3D)
	pline3DObj.Color = acBlue
	pline3DObj.Update


	' Query the coordinates of the polylines
	Dim get2Dpts As Variant
	Dim get3Dpts As Variant


	get2Dpts = pline2DObj.Coordinates
	get3Dpts = pline3DObj.Coordinates


	' Display the coordinates


	MsgBox ("2D polyline (red): " & vbCrLf & _
			get2Dpts(0) & ", " & get2Dpts(1) & vbCrLf & _
			get2Dpts(2) & ", " & get2Dpts(3) & vbCrLf & _
			get2Dpts(4) & ", " & get2Dpts(5))


	MsgBox ("3D polyline (blue): " & vbCrLf & _
			get3Dpts(0) & ", " & get3Dpts(1) & ", " & _
			get3Dpts(2) & vbCrLf & _
			get3Dpts(3) & ", " & get3Dpts(4) & ", " & _
			get3Dpts(5) & vbCrLf & _
			get3Dpts(6) & ", " & get3Dpts(7) & ", " & _
			get3Dpts(8))
End Sub