[用户交互] 选择集合
在与用户交互式的绘图的时候可能需要批量获取一些图形,而在这一批选择的时候你可能需要过滤一些不需要的类型自动排除在你选择的集合以外,下面这个例子就是只接受选择文本、圆、直线三种类型,其余的图形将不能选中。using System;<p>
</p><p>using Autodesk.AutoCAD.Runtime;</p><p>using Autodesk.AutoCAD.ApplicationServices;</p><p>using Autodesk.AutoCAD.DatabaseServices;</p><p>using Autodesk.AutoCAD.EditorInput;</p><p>
</p><p></p><p>namespace Sample</p><p>{</p><p> /// <summary></p><p> /// 类型过滤枚举类</p><p> /// </summary></p><p> public enum FilterType</p><p> {</p><p> Curve, Dimension, Polyline, BlockRef, Circle, Line, Arc, Text, MText</p><p> }</p><p>
</p><p> class Selection</p><p> {</p><p> </p><p> public void Select()</p><p> {</p><p> FilterType LineType = FilterType.Line;</p><p> FilterType TextType = FilterType.Text;</p><p> FilterType CircleType = FilterType.Circle;</p><p>
</p><p> FilterType[] Types = new FilterType;</p><p> Types = LineType;</p><p> Types = TextType;</p><p> Types = CircleType;</p><p> DBObjectCollection EntityCollection = GetSelection(Types);</p><p> }</p><p>
</p><p> public static DBObjectCollection GetSelection(FilterType[] tps)</p><p> {</p><p> Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;</p><p> Database db = doc.Database;</p><p> Editor ed = doc.Editor;</p><p> Entity entity = null;</p><p> DBObjectCollection EntityCollection = new DBObjectCollection();</p><p> PromptSelectionOptions selops = new PromptSelectionOptions();</p><p> // 建立选择的过滤器内容</p><p> TypedValue[] filList = new TypedValue;</p><p> filList = new TypedValue((int)DxfCode.Operator, "<or");</p><p> filList = new TypedValue((int)DxfCode.Operator, "or>");</p><p> for (int i = 0; i < tps.Length; i++)</p><p> {</p><p> filList = new TypedValue((int)DxfCode.Start, tps.ToString());</p><p> }</p><p> // 建立过滤器</p><p> SelectionFilter filter = new SelectionFilter(filList);</p><p> // 按照过滤器进行选择</p><p> PromptSelectionResult ents = ed.GetSelection(selops, filter);</p><p> if (ents.Status == PromptStatus.OK)</p><p> {</p><p> using (Transaction transaction = db.TransactionManager.StartTransaction())</p><p> {</p><p> SelectionSet SS = ents.Value;</p><p> foreach (ObjectId id in SS.GetObjectIds())</p><p> {</p><p> entity = (Entity)transaction.GetObject(id, OpenMode.ForWrite, true);</p><p> if (entity != null)</p><p> EntityCollection.Add(entity);</p><p> }</p><p> transaction.Commit();</p><p> }</p><p> }</p><p> return EntityCollection;</p><p> }</p><p> }</p><p>}</p>加载程序运行命令后框选图形上的对象后得到如下效果:
(*^__^*) 嘻嘻…… (*^__^*) 嘻嘻…… 顶......
楼下跟上..... (*^__^*) 嘻嘻…… 非常感谢!! 谢谢BIM大神… 顶!!!!!!!!!! 谢谢老师… 路过!!!
不发表意见…… 顶!!!!!!!!!!!!!!!!!!!!!!!!! (*^__^*) 嘻嘻…… 顶!!!!!!!!!! 顶......
楼下跟上..... 顶起来………… 顶!!!!!!!!!!!!!!!!!!!!!!!!! 顶!!!!!!!!!!
页:
[1]
2