How about My code?
Enjoy!
<CommandMethod("GSR")> _
Public Sub SelectedPlineToCode()
Dim editor As Editor = Application.DocumentManager.MdiActiveDocument.Editor
Dim db As Database = Application.DocumentManager.MdiActiveDocument.Database
Dim trans As Transaction = db.TransactionManager.StartTransaction()
Dim bt As BlockTable
Dim btr As BlockTableRecord
Try
Dim prEnt As New PromptEntityOptions(vbNewLine & "Select a polyline:")
prEnt.SetRejectMessage(vbNewLine & "You should choose a polyline!")
prEnt.AddAllowedClass(GetType(Polyline), True)
Dim prEntRes As PromptEntityResult = editor.GetEntity(prEnt)
If prEntRes.Status <> PromptStatus.OK Then Return
Dim id As ObjectId = prEntRes.ObjectId
Dim ent As Entity = DirectCast(trans.GetObject(id, OpenMode.ForRead), Entity)
Dim pl As Polyline = DirectCast(ent, Polyline)
Dim c As Curve = DirectCast(pl, Curve)
Dim sp As Double = c.StartParam
Dim ep As Double = c.EndParam
Dim p As Double
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
Dim pso As PromptStringOptions = New PromptStringOptions(vbNewLine & "Name The PLine,plz!: ")
pso.AllowSpaces = False
pso.DefaultValue = Chr(65 + Rnd() * 1000 Mod 26)
Dim res As PromptResult = ed.GetString(pso)
If res.Status <> PromptStatus.OK Then Return
Dim str As String = res.StringResult
Dim OpenFile As String = "C:\gsr.txt"
Dim filenumber As Integer = 1
Dim objFileW As System.IO.StreamWriter = My.Computer.FileSystem.OpenTextFileWriter("C:\gsr.txt", True)
Dim n As Integer = 0
Dim l As Integer = 0
Dim m As Integer = 0
objFileW.WriteLine("Dim " + str + " As New Autodesk.AutoCAD.DatabaseServices.Polyline()")
For p = sp To ep Step 1.0
Dim pt As Point3d = c.GetPointAtParameter(p)
Dim text As DBText = New DBText
l = n \ 26
m = n Mod 26
bt = trans.GetObject(db.BlockTableId, OpenMode.ForRead)
btr = trans.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForRead)
text.WidthFactor = 0.7
text.TextString = "Dim " + Chr(65 + l + 3) + Chr(65 + l) + Chr(65 + m) + " As New Point2d(" + _
pt.X.ToString(Format("N4")) + "," + pt.Y.ToString(Format("N4")) + ")"
text.Height = 0.001
text.Position = pt
If p = ep Then
If c.Closed = True Then
objFileW.WriteLine(str + ".Closed=True")
objFileW.WriteLine("---------------------------------------------------------------")
ElseIf c.Closed = False Then
objFileW.WriteLine(text.TextString)
objFileW.WriteLine(str + ".AddVertexAt(" & n & "," + Chr(65 + l + 3) + Chr(65 + l) + Chr(65 + m) + ",0,0,0)")
objFileW.WriteLine("---------------------------------------------------------------")
End If
ElseIf p <> ep Then
objFileW.WriteLine(text.TextString)
objFileW.WriteLine(str + ".AddVertexAt(" & n & "," + Chr(65 + l + 3) + Chr(65 + l) + Chr(65 + m) + ",0,0,0)")
End If
n += 1
Next
objFileW.Close()
trans.Commit()
Catch ex As Exception
trans.Abort()
MsgBox(ex.Message)
Finally
trans.Dispose()
End Try
End Sub