是一个简单的选择集基础实例,希望对新手有帮助,高手勿喷
然后还有一个问题:怎样才能做出 框选 的效果? (像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[1];
- typeSet[0] = 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();
|