Try this one that partially cutted from my project
'//
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.GraphicsInterface
Imports Autodesk.AutoCAD.ApplicationServices.Application
Imports AcadRT = Autodesk.AutoCAD.Runtime
Imports AcadED = Autodesk.AutoCAD.EditorInput
Imports AcadDB = Autodesk.AutoCAD.DatabaseServices
Imports AcadApp = Autodesk.AutoCAD.ApplicationServices.Application
Public Class Form1
'//
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
'//
Private Sub btnSelect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelect.Click
Dim tot As Double = CalcLength()
Me.Label1.Text = "Total Length:"
Me.txtTotal.Text = String.Format("{0}", tot)
End Sub
'//
Private Shared Function CalcLength() As Double
Dim tot As Double = 0
Dim ed As Editor = AcadApp.DocumentManager.MdiActiveDocument.Editor
Dim dxf() As TypedValue = {New TypedValue(DxfCode.Start, "LWPOLYLINE")}
Dim filt As New SelectionFilter(dxf)
Dim opts As PromptSelectionOptions = New PromptSelectionOptions
opts.MessageForAdding = "Select polylines to calculate the total length:"
opts.AllowDuplicates = False
opts.SingleOnly = False
Dim res As PromptSelectionResult = ed.GetSelection(opts, filt)
If res.Status <> PromptStatus.OK Then
Return 0
End If
Dim db As Database = HostApplicationServices.WorkingDatabase
Using tr As Transaction = db.TransactionManager.StartTransaction()
Dim sset As SelectionSet = res.Value
Dim IDs() As ObjectId = sset.GetObjectIds
Dim n As Integer = 0
For Each Id As ObjectId In IDs
Dim ent As Entity = tr.GetObject(IDs(n), OpenMode.ForRead)
Dim pl As Polyline = tr.GetObject(ent.ObjectId, OpenMode.ForRead)
Dim ln As Double = pl.GetDistanceAtParameter(pl.EndParam)
tot = tot + ln
n += 1
Next
' MessageBox.Show(String.Format("Total length = {0}", tot)) ' for debug only
tr.Dispose()
End Using
Return tot
End Function
End Class
'//
~'J'~