- UID
- 658062
- 积分
- 2147
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2008-10-22
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
//using System.Linq;
[CommandMethod("TotalLengthCS")]
public void testTotalLengthCS()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
StringBuilder sb = new StringBuilder();
sb.AppendLine("\tTotal Length:\n------------------------------------");
try
{
using (Transaction tr = db.TransactionManager.StartTransaction())
{
//------------------------------------------------------------------
// Create filter object, this filter can have any types to select, i.e. curves
SelectionFilter filter = new SelectionFilter(new TypedValue[]
{
new TypedValue(0, "LINE,ARC,SPLINE,CIRCLE,ELLIPSE,*POLYLINE") /*, new TypedValue(410, "~Model"),//<-- paper space only//*/
}
);
// Select objects on screen
PromptSelectionResult psr = ed.GetSelection(filter);
// Check if selection is succeed
if (psr.Status != PromptStatus.OK) return;
// See here for more: http://code.msdn.microsoft.com/101-LINQ-Samples-3fb9811b 101 LINQ Samples Csharp
// Grouping objects by name with sum of lengths
var data =
from e in psr.Value.GetObjectIds()
let ln= e.GetObject(OpenMode.ForRead) as Curve
group ln by ln.GetRXClass().DxfName into g
select new { ObjectName = g.Key, Subtotal = g.Sum(x => Math.Abs(x.GetDistanceAtParameter(x.EndParam - x.StartParam))) };
foreach (var n in data)
{
sb.AppendLine(string.Format("{0}\t{1:f6}", n.ObjectName, n.Subtotal));
}
System.Windows.Forms.MessageBox.Show(sb.ToString());
}
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.ToString());
}
}
|
|