The XY axis has variables for the length of its major axes and variables for the spacing of the tick marks along the axis. The tick marks have variable length. The X and Y axes should have their own inputs, not shared. In the simplest version all the tick marks on one axis have only one length (not like an inch ruler where there are 5 different lengths).

That makes 8 variables.

Xmin and Xmax -doubles for start and end point

Xscl – double for the distance between dividing tick marks

Xtick – double for the length of the tick.

The vertical Y axis has the same unique inputs not shared with the X axis.

Ymin, Ymax, Yscl and Ytick

When drawing a graph of an equation, we prefer to knit the segments together into one unit as a polyline. We dont have the polyline option with an axes. We have to draw with loose lines, but we can block them together afterward. Part 1 will draw the axis. Part 2 will add the lines to a selection set, and Part 3 will create a block entity from the selection set and final code posted.

The autocad Addline method requires two points which are each an array of 3 doubles. A line wrapper function is useful that takes the input and handles the details. We use the line wrapper to draw the axes and use a modified version of it to draw the tick marks.

at the top level, we call a specific xy axis with all the inputs. We can have as many of these as we need and can easily get the input from a userform.

Sub draw_std_axis() Call draw_xy_axis(-12, 12, 1, 0.5, -12, 12, 1, 0.5) End Sub Sub draw_xy_axis(Xmin As Double, Xmax As Double, Xscl As Double, Xtick As Double, _ Ymin As Double, Ymax As Double, Yscl As Double, Ytick As Double)

‘within the main sub are the independent subs for the X and Y axis

Call x_axis(Xmin, Xmax, Xscl, Xtick) Call y_axis(Ymin, Ymax, Yscl, Ytick)

here is the full program, just the geometry – minus selection set activity, blocking and input from a form.

Sub draw_std_axis() Call draw_xy_axis(-12, 12, 1, 0.5, -12, 12, 1, 0.5) End Sub Sub draw_trig_axis() Call draw_xy_axis(-pi * 2, pi * 2, pi / 4, pi / 8, -6, 6, 1, 0.25) End Sub Sub draw_xy_axis(Xmin As Double, Xmax As Double, Xscl As Double, Xtick As Double, _ Ymin As Double, Ymax As Double, Yscl As Double, Ytick As Double) Call connect_acad Call x_axis(Xmin, Xmax, Xscl, Xtick) Call y_axis(Ymin, Ymax, Yscl, Ytick) End Sub Sub x_axis(Xmin As Double, Xmax As Double, Xscl As Double, Xtick As Double) Dim X As Double Dim i As Integer, numpts As Integer numpts = (Xmax - Xmin) / Xscl 'this is the number of line segments numpts = numpts + 1 'there is always one more pt than line segment Call line(Xmin, 0, Xmax, 0) For i = 1 To numpts X = Xmin + ((i - 1) * Xscl) If X <> 0 Then Call draw_x_tick(X, Xtick) End If Next i End Sub Sub y_axis(Ymin As Double, Ymax As Double, Yscl As Double, Ytick As Double) Dim Y As Double Dim i As Integer, numpts As Integer numpts = (Ymax - Ymin) / Yscl 'this is the number of line segments numpts = numpts + 1 'there is always one more pt than line segment Call line(0, Ymin, 0, Ymax) For i = 1 To numpts Y = Ymin + ((i - 1) * Yscl) If Y <> 0 Then Call draw_y_tick(Y, Ytick) End If Next i End Sub 'the line wrapper Sub line(p1 As Double, p2 As Double, p3 As Double, p4 As Double) Dim lineobj As AcadLine Dim pt1(0 To 2) As Double, pt2(0 To 2) As Double pt1(0) = p1: pt1(1) = p2: pt1(2) = 0 pt2(0) = p3: pt2(1) = p4: pt2(2) = 0 Set lineobj = acadApp.ActiveDocument.ModelSpace.AddLine(pt1, pt2) End Sub Sub draw_x_tick(X As Double, Xtick As Double) 'line from (X, 0-Xtick/2) to (X, 0+Xtick/2) Dim lineobj As AcadLine Dim pt1(0 To 2) As Double, pt2(0 To 2) As Double pt1(0) = X: pt1(1) = -Xtick / 2: pt1(2) = 0 pt2(0) = X: pt2(1) = Xtick / 2: pt2(2) = 0 Set lineobj = acadApp.ActiveDocument.ModelSpace.AddLine(pt1, pt2) End Sub Sub draw_y_tick(Y As Double, Ytick As Double) 'line from (0-Ytick/2,y) to (0+Ytick/2,y) Dim lineobj As AcadLine Dim pt1(0 To 2) As Double Dim pt2(0 To 2) As Double pt1(0) = -Ytick / 2: pt1(1) = Y: pt1(2) = 0 pt2(0) = Ytick / 2: pt2(1) = Y: pt2(2) = 0 Set lineobj = acadApp.ActiveDocument.ModelSpace.AddLine(pt1, pt2) End Sub