- 积分
- 603
- 明经币
- 个
- 注册时间
- 2011-7-31
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
本帖最后由 介之推 于 2011-8-12 12:40 编辑
大家好,通过定义选择集来选择时需要在窗口上用鼠标拖动光标来选择,有没有不用拖选就能直接选中所有的直线?下面的代码需要手动选才行。
[CommandMethod("AllLines")]
public void seletcAllLines()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
try
{
//define the criteria for selecting lines only
TypedValue[] tv = new TypedValue[] { new TypedValue((int)DxfCode.Start, "LINE") };
SelectionFilter flt = new SelectionFilter(tv);
/*This method needs to drag the cursor,which I think is not smart.
I will want to improve*/
PromptSelectionOptions optSel = new PromptSelectionOptions();
optSel.MessageForAdding = "You will need to drag this cursor to select.";
PromptSelectionResult resSel = ed.GetSelection(optSel,flt);
SelectionSet selSet = resSel.Value;
ObjectId[] ids = selSet.GetObjectIds();
foreach (ObjectId sSetEntId in ids)
{
Entity ent = (Entity)trans.GetObject(sSetEntId, OpenMode.ForWrite);
if (ent.GetType().Name=="Line") //请问有更好的判断方法吗?typeof(ent) is Line在这里出错。
{
Line myLine = (Line)trans.GetObject(sSetEntId, OpenMode.ForWrite);
ed.WriteMessage("\n"+myLine.StartPoint.ToString()+ myLine.EndPoint.ToString());
}
}
trans.Commit();
}
catch(System.Exception ex)
{
ed.WriteMessage(ex.Message + "\n" + ex.StackTrace);
}
}
}
|
|