乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 63|回复: 5

如何不用拖选就能把所有的直线选中

[复制链接]

8

主题

12

帖子

1

银币

初来乍到

Rank: 1

铜币
44
发表于 2011-8-12 10:26:00 | 显示全部楼层 |阅读模式
大家好,通过定义选择集来选择时需要在窗口上用鼠标拖动光标来选择,有没有不用拖选就能直接选中所有的直线?下面的代码需要手动选才行。
[CommandMethod("AllLines")]
        public void seletcAllLines()
        {
            Document doc = Autodesk..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);
                }
            }
        }
回复

使用道具 举报

1

主题

10

帖子

6

银币

初来乍到

Rank: 1

铜币
14
发表于 2011-8-12 16:23:00 | 显示全部楼层
试试直接用ObjectId——
foreach (ObjectId sSetEntId in ids)
{
                        
       //Entity ent = (Entity)trans.GetObject(sSetEntId, OpenMode.ForWrite);
       if (sSetEntId.ObjectClass.DFXName == "LINE")
       {
            Line myLine = (Line)trans.GetObject(sSetEntId, OpenMode.ForWrite);
            ed.WriteMessage("\n"+myLine.StartPoint.ToString()+ myLine.EndPoint.ToString());
       }
   
}
回复

使用道具 举报

19

主题

154

帖子

5

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
230
发表于 2011-8-13 10:47:00 | 显示全部楼层
遍历数据库
回复

使用道具 举报

32

主题

651

帖子

8

银币

中流砥柱

Rank: 25

铜币
779
发表于 2011-8-13 10:55:00 | 显示全部楼层
if (ent.GetType().Name=="Line") //请问有更好的判断方法吗?typeof(ent) is Line在这里出错
1,ent is Line
2, ent.GetType(). == typeof(Line)
3,public Autodesk.AutoCAD.EditorInput.PromptSelectionResult SelectAll(Autodesk.AutoCAD.EditorInput.SelectionFilter filter)
    Autodesk.AutoCAD.EditorInput.Editor 的成员
回复

使用道具 举报

8

主题

138

帖子

5

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
170
发表于 2011-8-14 14:40:00 | 显示全部楼层
vs2008的话试试linq吧
回复

使用道具 举报

75

主题

306

帖子

10

银币

中流砥柱

Rank: 25

铜币
606
发表于 2011-8-15 00:20:00 | 显示全部楼层
TypedValue[] tv = new TypedValue[] { new TypedValue(0, "LINE") };
有了这句话,不可能选中非line对象的
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-15 16:21 , Processed in 0.413529 second(s), 64 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表