- 积分
- 1142
- 明经币
- 个
- 注册时间
- 2011-2-28
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
[CommandMethod("my")]
public void my1()
{
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
try
{
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
BlockTable acBlkTbl;
acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord acBlkTblRec;
acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
OpenMode.ForWrite) as BlockTableRecord;
PromptSelectionOpti** pso = new PromptSelectionOpti**();
PromptSelectionResult psr = ed.GetSelection(pso);
if (psr.Status == PromptStatus.OK)
{
Selecti**et ss = psr.Value;
int lcount = 0;
int n = ss.Count;
double result = 0;
for (int i = 0; i < n; i++)
{
Entity ent = acTrans.GetObject(ss[i].ObjectId, OpenMode.ForWrite) as Entity;
if (ent is Line)
{
Line l = ent as Line;
result += l.Length;
lcount++;
ed.WriteMessage("\n实体" + lcount + "的长度为:" + l.Length);
}
if (ent is Circle)
{
Circle c = ent as Circle;
result += c.Circumference;
lcount++;
ed.WriteMessage("\n实体" + lcount + "的长度为:" + c.Circumference);
}
if (ent is Ellipse)
{
Ellipse e = ent as Ellipse;
double zc = Math.PI * (e.MajorRadius + e.MinorRadius);
result += zc;
lcount++;
ed.WriteMessage("\n实体" + lcount + "的长度为:" + zc);
}
if (ent is Arc)
{
Arc arc = ent as Arc;
result += arc.Length;
lcount++;
ed.WriteMessage("\n实体" + lcount + "的长度为:" + arc.Length);
}
if (ent is Spline)
{
Spline s = ent as Spline;
Curve c = s.ToPolyline();
Polyline pl = c as Polyline;
result += pl.Length;
lcount++;
ed.WriteMessage("\n实体" + lcount + "的长度为:" + pl.Length);
}
if (ent is Polyline)
{
Polyline pl = ent as Polyline;
result += pl.Length;
lcount++;
ed.WriteMessage("\n实体" + lcount + "的长度为:" + pl.Length);
}
// else
//{
// lcount++;
// ed.WriteMessage("\n实体" + lcount + "未计入总长!");
// }
}
ed.WriteMessage("\n线段的总长度为:{0}", result);
}
else ed.WriteMessage("\n未选中线段!"); ;
acTrans.Commit();
}
}
catch (System.Exception)
{
Application.ShowAlertDialog("error");
}
}
|
|