- UID
- 658062
- 积分
- 2147
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2008-10-22
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
[CommandMethod("tot")]
public void testTotalLength()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
double total = 0;
Transaction tr = doc.TransactionManager.StartOpenCloseTransaction();
using (tr)
{
TypedValue[] tv = new TypedValue[] { new TypedValue((int)DxfCode.Start, "*LINE,ARC") };
SelectionFilter flt = new SelectionFilter(tv);
PromptSelectionResult res = ed.GetSelection(flt);
if (res.Status != PromptStatus.OK) return;
SelectionSet sset = res.Value;
if (sset.Count == 0) return;
foreach (SelectedObject sobj in sset)
{
Entity ent = (Entity)tr.GetObject(sobj.ObjectId, OpenMode.ForRead);
Curve curv = ent as Curve;
if (curv != null)
total += curv.GetDistanceAtParameter(curv.EndParam);
}
ed.WriteMessage("\nTotal Length:\t{0:f3}\n",total);
}
}
[CommandMethod("toa")]
public void testTotalArea()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
double total = 0;
Transaction tr = doc.TransactionManager.StartOpenCloseTransaction();
using (tr)
{
// build filter to select closed curves and circles
TypedValue[] tv = new TypedValue[]
{ new TypedValue(-4, "<or"),
new TypedValue(-4, "<and"),
new TypedValue(0, "*LINE"),
new TypedValue(70, 1), new TypedValue(-4, "and>"),
new TypedValue(0, "CIRCLE"),
new TypedValue(-4, "or>") };
SelectionFilter flt = new SelectionFilter(tv);
PromptSelectionResult res = ed.GetSelection(flt);
if (res.Status != PromptStatus.OK) return;
SelectionSet sset = res.Value;
if (sset.Count == 0) return;
foreach (SelectedObject sobj in sset)
{
Entity ent = (Entity)tr.GetObject(sobj.ObjectId, OpenMode.ForRead);
Curve curv = ent as Curve;
if (curv != null)
total += curv.Area;
}
ed.WriteMessage("\nTotal Area:\t{0:f3}\n", total);
}
} |
|