About Creating Lines (VBA/ActiveX)

The line is the most basic object in AutoCAD. You can create a variety of lines—single lines, and multiple line segments with and without arcs.

In general, you draw lines by specifying coordinate points. The default linetype is CONTINUOUS, an unbroken line, but various linetypes are available that use dots and dashes.

To create a line, use one of the following methods:

AddLine
Creates a line passing through two points.
AddLightweightPolyline
Creates a 2D lightweight polyline from a list of vertices.
AddMLine
Creates a multiline.
AddPolyline
Creates a 2D or 3D polyline.

Standard lines and multilines are created on the XY plane of the world coordinate system. Polylines and Lightweight Polylines are created in the object coordinate system (OCS).

Create a Polyline object

This example uses the AddLightweightPolyline method to create a simple two-segment polyline using the 2D coordinates (2,4), (4,2), and (6,4).

Sub Ch4_AddLightWeightPolyline()
  Dim plineObj As AcadLWPolyline
  Dim points(0 To 5) As Double

  ' Define the 2D polyline points
  points(0) = 2: points(1) = 4
  points(2) = 4: points(3) = 2
  points(4) = 6: points(5) = 4

  ' Create a light weight Polyline object in model space
  Set plineObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(points)
  ThisDrawing.Application.ZoomAll
End Sub