- <CommandMethod("SLenth")> Public Sub sumLineLength()
- Dim db As Database = HostApplicationServices.WorkingDatabase
- Dim ed As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
- Dim fType As TypedValue = New TypedValue(DxfCode.Start, "Line")
- Dim fTypeList() As TypedValue = {fType}
- Dim myFilter As New SelectionFilter(fTypeList)
- Dim proSset As New PromptSelectionOptions
- proSset.MessageForAdding = "Please choose some entities:"
- Dim resSset As PromptSelectionResult = ed.GetSelection(proSset, myFilter)
- Dim lineSset As SelectionSet = resSset.Value
- Dim objIds As ObjectId() = lineSset.GetObjectIds()
- If lineSset.Count = 0 Then
- Else
- Using trans As Transaction = db.TransactionManager.StartTransaction
- Dim lineLenth As Double = 0.0
- For Each objId As ObjectId In objIds
- Dim myLine As Line = trans.GetObject(objId, OpenMode.ForRead)
- lineLenth = lineLenth + myLine.Length()
- Next
- ed.WriteMessage(vbcrlf & "The total lines' length is:" & lineLenth.ToString)
- End Using
- End If
- End Sub
|