# Autocad VBA Parametrics – 2 – Polyline Method

The autocad lightweightpolyline is the method of choice for drawing parametric plane figures if it is an option. But assembling an array of 30 or so points can be tedious. Here is a sub i wrote several months ago, and to be honest, it is a complete mystery now. the only way i can work on it is to plot it out and start listing points. So i am going to generalize the method and come up with an easier standard procedure for drawing parametric polyline objects.

Sub orig_OS_skin(A As Double, B As Double)
Dim pt(1 To 36) As Double

pt(1) = 0.21875: pt(2) = A + 0.5 - 1
pt(3) = 0.21875: pt(4) = A + 0.5
pt(5) = 0: pt(6) = A + 0.5
pt(7) = 0: pt(8) = 0
pt(9) = B + 0.5 - 1.25: pt(10) = 0
pt(11) = B + 0.5 - 1.0625: pt(12) = 0.1875
pt(13) = B + 0.5: pt(14) = 0.1875
pt(15) = B + 0.5: pt(16) = 0.40625
pt(17) = B + 0.5 - 0.875: pt(18) = 0.40625
pt(19) = B + 0.5 - 0.875: pt(20) = 0.34375
pt(21) = B + 0.5 - 0.0625: pt(22) = 0.34375
pt(23) = B + 0.5 - 0.0625: pt(24) = 0.25
pt(25) = B + 0.5 - 1.08839: pt(26) = 0.25
pt(27) = B + 0.5 - 1.27589: pt(28) = 0.0625
pt(29) = 0.0625: pt(30) = 0.0625
pt(31) = 0.0625: pt(32) = A + 0.5 - 0.0625
pt(33) = 0.15625: pt(34) = A + 0.5 - 0.0625
pt(35) = 0.15625: pt(36) = A + 0.5 - 1
objent.Closed = True
objent.Update

Set objpersistent = objent
End Sub

the first task is to draw a single polyline object. You cannot automate an object if you cannot draw it. if you have drawn it 100 times you will do a better job automating it than if you have barely drawn it. Just like plotting a curve, place it as conveniently as possible at 0,0. Visualize it sitting on the xy axis. Keep your parametric variables as convenient as possible. Start listing points by moving in the direction of the positive X axis. sweep around the screen in a counterclockwise direction as a standard procedure. Locate the first point at 0,0 if possible. The second point should be to the right. Use excel to list just the X values. it is simpler to separate the listings of X and Y values and measure or calculate them separately. Work in the parametric calculations as you go. Make dimensions and measurements on the drawing as needed. After you have gone all around the object listing the X values, do the same thing for Y. This is the key step.

The program listing above that dimensions an array (1 to 36) for 18 points then loads a value into each index location is the brute force normal straightforward approach. We can instead create a polyline wrapper program. The array function only requires the data to be separated by commas. the Polyline method will not use that array directly, but we can create a transfer method in the wrapper. the wrapper will also measure the length of the array. Create a new sub and paste the values just entered into the spreadsheet into the sub.

Sub new_poly_draw(A As Double, B As Double)
Dim pt As Variant
pt = array(

Paste here

Call draw_array(pt)
End Sub
Sub new_poly_draw(A As Double, B As Double)
Dim pt As Variant
pt = array(

0   0
B-1.25  0
B-1.0625    0.1875
B 0.1875
B 0.40625
B-.875  0.40625
B-.875  0.34375
B-.0625 0.34375
B-.0625 0.25
B-1.0884    0.25
B-1.2759    0.0625
0.0625  0.0625
0.0625  A-.0625
0.15625 A-.0625
0.15625 A-1
0.21875 A-1
0.21875 A
0   A

Call draw_array(pt)
End Sub

now put commas between values and put your line continuations wherever you want.

Sub new_poly_draw(A As Double, B As Double)
Dim pt As Variant

pt = Array(0, 0, B - 1.25, 0, B - 1.0625, 0.1875, _
B, 0.1875, B, 0.40625, B - 0.875, 0.40625, B - 0.875, 0.34375, _
B - 0.0625, 0.34375, B - 0.0625, 0.25, B - 1.0884, 0.25, B - 1.2759, 0.0625, _
0.0625, 0.0625, 0.0625, A - 0.0625, 0.15625, A - 0.0625, 0.15625, A - 1, _
0.21875, A - 1, 0.21875, A, 0, A)

Call draw_array(pt)
End Sub

and you are done, because you have this wrapper to run it

Sub draw_array(pt As Variant)
Dim pt2() As Double
Dim i As Integer
Dim lower As Integer, upper As Integer
lower = LBound(pt)
upper = UBound(pt)

ReDim pt2(lower To upper)
For i = lower To upper
pt2(i) = pt(i)
Next i