C# 选择集基础实例
是一个简单的选择集基础实例,希望对新手有帮助,高手勿喷然后还有一个问题:怎样才能做出 框选 的效果? (像AutoCAD的框选效果)
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
Database db = HostApplicationServices.WorkingDatabase;
DocumentLock dlock = Application.DocumentManager.MdiActiveDocument.LockDocument();
using (Transaction tran = db.TransactionManager.StartTransaction())
{
SelectionSet selSet;
//输入一种选择集过滤的实体类型 如circle line text
PromptStringOptions stringOpts = new PromptStringOptions("\n请输入实体类型:");
PromptResult stringResult = ed.GetString(stringOpts);
if (stringResult.Status != PromptStatus.OK) return;
//输入结束后,将其加入选择集筛选条件
TypedValue[] typeSet = new TypedValue;
typeSet = new TypedValue((int)DxfCode.Start, stringResult.StringResult);
SelectionFilter sFilter = new SelectionFilter(typeSet);
//①用户选择其实体 (选择集方式一)
//PromptSelectionResult selectResult = ed.GetSelection(sFilter);
//②用户选择区域 (选择集方式二)
Point3d onePnt,otherPnt;
PromptPointOptions pntOpts = new PromptPointOptions("\n请选择起始点:");
PromptPointResult pntResult = ed.GetPoint(pntOpts);
if (pntResult.Status != PromptStatus.OK) return;
onePnt = pntResult.Value;
pntOpts = new PromptPointOptions("\n请选择结束点:");
pntOpts.BasePoint = onePnt;
//是否虚线显示
//pntOpts.UseDashedLine = true;
pntOpts.UseBasePoint = true;
pntResult = ed.GetPoint(pntOpts);
if (pntResult.Status != PromptStatus.OK) return;
otherPnt = pntResult.Value;
//多种选择方法
//PromptSelectionResult selectResult = ed.SelectCrossingWindow(onePnt, otherPnt, sFilter);
PromptSelectionResult selectResult = ed.SelectWindow(onePnt, otherPnt, sFilter);
if (selectResult.Status != PromptStatus.OK) return;
selSet = selectResult.Value;
ed.WriteMessage(selSet.Count.ToString());
}
dlock.Dispose();
找到了另外一种方法来实现了。
站内相关示例帖子:
http://bbs.mjtd.com/forum.php?mod=viewthread&tid=84859
http://www.objectarx.net/forum.php?mod=viewthread&tid=5811
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
Database db = HostApplicationServices.WorkingDatabase;
DocumentLock dlock = Application.DocumentManager.MdiActiveDocument.LockDocument();
using (Transaction tran = db.TransactionManager.StartTransaction())
{
SelectionSet selSet;
//输入一种选择集过滤的实体类型 如circle line text
PromptStringOptions stringOpts = new PromptStringOptions("\n请输入实体类型:");
PromptResult stringResult = ed.GetString(stringOpts);
if (stringResult.Status != PromptStatus.OK) return;
//输入结束后,将其加入选择集筛选条件
TypedValue[] typeSet = new TypedValue;
typeSet = new TypedValue((int)DxfCode.Start, stringResult.StringResult);
SelectionFilter sFilter = new SelectionFilter(typeSet);
//用户选择区域
PromptSelectionOptions selectOpts = new PromptSelectionOptions();
PromptSelectionResult selectResult = ed.GetSelection(selectOpts,sFilter);
if (selectResult.Status != PromptStatus.OK) return;
selSet = selectResult.Value;
//得到该用户选择区域的左下角 和 右上角
CrossingOrWindowSelectedObject o = (CrossingOrWindowSelectedObject)selSet;
PickPointDescriptor[] p = o.GetPickPoints();
Point2d minPoint = new Point2d(p.PointOnLine.X, p.PointOnLine.Y);
Point2d maxPoint = new Point2d(p.PointOnLine.X, p.PointOnLine.Y);
ed.WriteMessage("\n" + minPoint.ToString());
ed.WriteMessage("\n" + maxPoint.ToString());
}
dlock.Dispose();
呵呵,比较基础。。。。。。
页:
[1]