乐筑天下

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

C# 选择集基础实例

[复制链接]

9

主题

26

帖子

2

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
62
发表于 2013-7-31 17:31:00 | 显示全部楼层 |阅读模式
是一个简单的选择集基础实例,希望对新手有帮助,高手勿喷
然后还有一个问题:怎样才能做出 框选 的效果? (像的框选效果)
           
  1. Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
  2.             Database db = HostApplicationServices.WorkingDatabase;
  3.             DocumentLock dlock = Application.DocumentManager.MdiActiveDocument.LockDocument();
  4.             using (Transaction tran = db.TransactionManager.StartTransaction())
  5.             {
  6.                 SelectionSet selSet;
  7.                 //输入一种选择集过滤的实体类型   如  circle   line text
  8.                 PromptStringOptions stringOpts = new PromptStringOptions("\n请输入实体类型:");
  9.                 PromptResult stringResult = ed.GetString(stringOpts);
  10.                 if (stringResult.Status != PromptStatus.OK) return;
  11.                 //输入结束后,将其加入选择集筛选条件
  12.                 TypedValue[] typeSet = new TypedValue[1];
  13.                 typeSet[0] = new TypedValue((int)DxfCode.Start, stringResult.StringResult);
  14.                 SelectionFilter sFilter = new SelectionFilter(typeSet);
  15.                 //①用户选择其实体   (选择集方式一)
  16.                 //PromptSelectionResult selectResult = ed.GetSelection(sFilter);
  17.                 //②用户选择区域        (选择集方式二)
  18.                 Point3d onePnt,otherPnt;
  19.                 PromptPointOptions pntOpts = new PromptPointOptions("\n请选择起始点:");
  20.                 PromptPointResult pntResult = ed.GetPoint(pntOpts);
  21.                 if (pntResult.Status != PromptStatus.OK) return;
  22.                 onePnt = pntResult.Value;
  23.                 pntOpts = new PromptPointOptions("\n请选择结束点:");
  24.                 pntOpts.BasePoint = onePnt;
  25.                 //是否虚线显示
  26.                 //pntOpts.UseDashedLine = true;
  27.                 pntOpts.UseBasePoint = true;
  28.                 pntResult = ed.GetPoint(pntOpts);
  29.                 if (pntResult.Status != PromptStatus.OK) return;
  30.                 otherPnt = pntResult.Value;
  31.                
  32.                 //多种选择方法
  33.                 //PromptSelectionResult selectResult = ed.SelectCrossingWindow(onePnt, otherPnt, sFilter);
  34.                 PromptSelectionResult selectResult = ed.SelectWindow(onePnt, otherPnt, sFilter);
  35.                 if (selectResult.Status != PromptStatus.OK) return;
  36.                 selSet = selectResult.Value;
  37.                 ed.WriteMessage(selSet.Count.ToString());
  38.             }
  39.             dlock.Dispose();
回复

使用道具 举报

9

主题

26

帖子

2

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
62
发表于 2013-8-1 08:39:00 | 显示全部楼层
找到了另外一种方法来实现了。
站内相关示例帖子:
http://bbs.mjtd.com/forum.php?mod=viewthread&tid=84859
  1. Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
  2. Database db = HostApplicationServices.WorkingDatabase;
  3. DocumentLock dlock = Application.DocumentManager.MdiActiveDocument.LockDocument();
  4. using (Transaction tran = db.TransactionManager.StartTransaction())
  5. {
  6.     SelectionSet selSet;
  7.     //输入一种选择集过滤的实体类型   如  circle   line text
  8.     PromptStringOptions stringOpts = new PromptStringOptions("\n请输入实体类型:");
  9.     PromptResult stringResult = ed.GetString(stringOpts);
  10.     if (stringResult.Status != PromptStatus.OK) return;
  11.     //输入结束后,将其加入选择集筛选条件
  12.     TypedValue[] typeSet = new TypedValue[1];
  13.     typeSet[0] = new TypedValue((int)DxfCode.Start, stringResult.StringResult);
  14.     SelectionFilter sFilter = new SelectionFilter(typeSet);
  15.     //用户选择区域
  16.     PromptSelectionOptions selectOpts = new PromptSelectionOptions();
  17.     PromptSelectionResult selectResult = ed.GetSelection(selectOpts,sFilter);
  18.     if (selectResult.Status != PromptStatus.OK) return;
  19.     selSet = selectResult.Value;
  20.     //得到该用户选择区域的左下角 和 右上角
  21.     CrossingOrWindowSelectedObject o = (CrossingOrWindowSelectedObject)selSet[0];
  22.     PickPointDescriptor[] p = o.GetPickPoints();
  23.     Point2d minPoint = new Point2d(p[3].PointOnLine.X, p[3].PointOnLine.Y);
  24.     Point2d maxPoint = new Point2d(p[1].PointOnLine.X, p[1].PointOnLine.Y);
  25.     ed.WriteMessage("\n" + minPoint.ToString());
  26.     ed.WriteMessage("\n" + maxPoint.ToString());
  27. }
  28. dlock.Dispose();

回复

使用道具 举报

5

主题

29

帖子

1

银币

初来乍到

Rank: 1

铜币
49
发表于 2013-8-23 09:53:00 | 显示全部楼层
呵呵,比较基础。。。。。。
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-14 13:12 , Processed in 0.399877 second(s), 58 queries .

© 2020-2025 乐筑天下

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