长度求和?
拾取直线的长度后,我想在命令行显示拾取直线长度之和 请问斑竹 这句代码该怎么写?ed.WriteMessage(??????) <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 请问在C#中 该怎么写呢?小弟愚笨 恳请斑竹帮个忙
public static void Test2()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
var resSel =
ed.GetSelection(
new SelectionFilter(
new TypedValue[]
{
new TypedValue(0, "line")
}));
if (resSel.Status != PromptStatus.OK)
return;
using (var tr = db.TransactionManager.StartTransaction())
{
var sum =
resSel.Value.GetObjectIds()
.Select(id => tr.GetObject(id, OpenMode.ForRead) as Line)
.Select(line => line.Length)
.Sum();
ed.WriteMessage("直线的总长度为:{0}", sum);
}
} 感谢飞狐大哥 问题已经解决
页:
[1]