- 积分
- 24557
- 明经币
- 个
- 注册时间
- 2004-3-17
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
本帖最后由 雪山飞狐_lzh 于 2014-8-11 09:02 编辑
在Lisp版看见这个问题
感觉用Linq应该是最简单的,就试着写了下
- [CommandMethod("cc")]
- public static void CC()
- {
- Document doc = Application.DocumentManager.MdiActiveDocument;
- Editor ed = doc.Editor;
- Database db = doc.Database;
- PromptEntityOptions optsEnt = new PromptEntityOptions("\n请选择同心圆:");
- optsEnt.SetRejectMessage("\n类型选择错误!");
- optsEnt.AddAllowedClass(typeof(Circle), false);
- double[] rads = null;
- PromptEntityResult resEnt = ed.GetEntity(optsEnt);
- while (resEnt.Status != PromptStatus.Cancel)
- {
- if (resEnt.Status == PromptStatus.OK)
- {
- using (Transaction tr = db.TransactionManager.StartTransaction())
- {
- var cir = tr.GetObject(resEnt.ObjectId, OpenMode.ForRead) as Circle;
- var ss1 = ed.SelectAll(new ResultList { { 0, "circle" }, { 10, cir.Center } });
- if (ss1.Value.Count == 2)
- {
- rads =
- (from ObjectId id in ss1.Value.GetObjectIds()
- let c = tr.GetObject(id, OpenMode.ForRead) as Circle
- select c.Radius)
- .ToArray();
- break;
- }
- }
- }
- ed.WriteMessage("\n你选择的不是同心圆!");
- resEnt = ed.GetEntity(optsEnt);
- }
- if (resEnt.Status == PromptStatus.Cancel)
- return;
- var ss = ed.SelectAll(
- new ResultList {
- { 0, "circle" },
- { -4, "<or"},
- { 40, rads[0] },
- { 40, rads[1] },
- { -4, "or>"}
- });
- using (Transaction tr = db.TransactionManager.StartTransaction())
- {
- var q =
- from ObjectId id in ss.Value.GetObjectIds()
- let c = tr.GetObject(id, OpenMode.ForRead) as Circle
- group id by c.Center;
- var q2 = q.Where(g => g.Count() == 2).SelectMany(g => g).ToArray();
- ed.SetImpliedSelection(q2);
- }
- }
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?注册
x
|