使用Linq选择同心圆
本帖最后由 雪山飞狐_lzh 于 2014-8-11 09:02 编辑在Lisp版看见这个问题
感觉用Linq应该是最简单的,就试着写了下
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 },
{ 40, rads },
{ -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);
}
}
严重支持大侠。可惜只会LISP! ResultList类是自定义的?还是哪个父类里面的?我这里提示没有 http://bbs.mjtd.com/forum.php?mod=viewthread&tid=79849&extra=page%3D1%26filter%3Dtypeid%26typeid%3D36%26typeid%3D36 雪山飞狐_lzh 发表于 2014-8-23 09:47 static/image/common/back.gif
http://bbs.mjtd.com/forum.php?mod=viewthread&tid=79849&extra=page%3D1%26filter%3Dtypeid%26typeid%3D3 ...
谢谢!我刚才自己已经写了一半了。。。还是版主写的好,果断扔了我的半成品
页:
[1]