Try these functions instead:
'//
Public Shared Function TotalLength() As Double
Dim totlen As Double = 0
Dim ed As Editor = Application.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 'by suit
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.Length
totlen = totlen + ln
n += 1
Next
MessageBox.Show(String.Format("Total length = {0}", totlen)) ' for debug only
tr.Dispose()
End Using
Return totlen
End Function
'//
'//
'//
Public Shared Function TotalArea() As Double
Dim totar As Double = 0
Dim ed As Editor = Application.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 'by suit
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 ar As Double = pl.Area
totar = totar + ar
n += 1
Next
MessageBox.Show(String.Format("Total area = {0}", totar)) ' for debug only
tr.Dispose()
End Using
Return totar
End Function
'//
~'J'~