![]() |
【转帖】类似lisp选择方式的c#选择集获取函数 - 精华帖集合
类似lisp选择方式的c#选择集获取函数 - 精华帖集合
www.dimcax.com 类似lisp选择方式的c#选择集获取函数 习惯lisp选择集的朋友可能喜欢 支持小狼!但我建议把代码帖出来,使阅读更加方便。 想贴,提示代码太长了贴不上去 public enum selectiontype { all = 0, last = 1, previous = 2, window = 3, windowpolygon = 4, crossingpolygon = 5, crossingwindow = 6, fence = 7, select = 8 } public class selectionobject { /// <summary> /// 获取单个对象id /// </summary> /// <param name="msg">选择提示</param> /// <returns></returns> public objectid getobjonly(string msg) { promptselectionoptions options = new promptselectionoptions(); options.singleonly = true; options.singlepickinspace = true; options.messageforadding = "select an entity:"; acadpropers.editor.writemessage(msg); promptselectionresult result = acadpropers.editor.getselection(options); if (result.status != promptstatus.ok) { acadpropers.editor.writemessage("用户取消查看!"); return objectid.null; } objectid[] ids = result.value.getobjectids(); return ids[0]; } /// <summary> /// 选择当前文档所有图形对象 /// </summary> /// <returns></returns> public objectid[] ssget() { objectid[] ids = null; try { promptselectionresult result = acadpropers.editor.selectall(); if (result.status == promptstatus.ok) ids = result.value.getobjectids(); } catch (system.exception) { return null; } return ids; } /// <summary> /// 更具方法选择对象支持 /// all 全选方式, /// last 最后一个对象, /// previous 最后一个选择集, /// </summary> /// <param name="seltype">选择方法</param> /// <returns></returns> public objectid[] ssget(selectiontype seltype) { objectid[] ids = null; try { promptselectionresult result = null; switch (seltype) { case selectiontype.all: result = acadpropers.editor.selectall(); break; case selectiontype.last: result = acadpropers.editor.selectlast(); break; case selectiontype.previous: result = acadpropers.editor.selectprevious(); break; default: return null; } if (result.status == promptstatus.ok) ids = result.value.getobjectids(); } catch (system.exception) { return null; } return ids; } /// <summary> /// 根据条件选择当前文档中图形对象 /// </summary> /// <param name="fillist">过滤条件</param> /// <returns></returns> public objectid[] ssget(selectionfilter fillist) { objectid[] ids = null; try { promptselectionresult result = acadpropers.editor.selectall(fillist); if (result.status == promptstatus.ok) ids = result.value.getobjectids(); } catch (system.exception) { return null; } return ids; } 复制代码 /// <summary> /// 用户选择 /// 可选这单选或多选模式 /// </summary> /// <param name="selectionmessage">选择提示</param> /// <param name="fillist">过滤器</param> /// <param name="selectonly">是否单选</param> /// <returns></returns> public objectid[] ssget(string selectionmessage, selectionfilter fillist, bool selectonly) { objectid[] ids = null; try { promptselectionresult result = null; promptselectionoptions options = new promptselectionoptions(); options.messageforadding = selectionmessage; if (selectonly) { options.singleonly = true; options.singlepickinspace = true; } result = acadpropers.editor.getselection(options, fillist); if (result.status == promptstatus.ok) ids = result.value.getobjectids(); else acadpropers.editor.writemessage("用户取消选择!"); } catch (system.exception) { return null; } return ids; } /// <summary> /// 用户选择 /// 可选这单选或多选模式 /// </summary> /// <param name="selectionmessage">选择提示</param> /// <param name="selectonly">是否单选</param> /// <returns></returns> public objectid[] ssget(string selectionmessage, bool selectonly) { objectid[] ids = null; try { promptselectionresult result = null; promptselectionoptions options = new promptselectionoptions(); options.messageforadding = selectionmessage; if (selectonly) { options.singleonly = true; options.singlepickinspace = true; } result = acadpropers.editor.getselection(options); if (result.status == promptstatus.ok) ids = result.value.getobjectids(); else acadpropers.editor.writemessage("用户取消选择!"); } catch (system.exception) { return null; } return ids; } /// <summary> /// 更具坐标、过滤器选择对象,支持 /// windowpolygon 多边形内, crossingpolygon多边形相交, fence 线相交 /// </summary> /// <param name="seltype">选择类型</param> /// <param name="pnt3dcoll">坐标集</param> /// /// <param name="fillist">过滤器</param> /// <returns></returns> public objectid[] ssget(selectiontype seltype, point3dcollection pnt3dcoll, selectionfilter fillist) { promptselectionresult result = null; objectid[] ids = null; try { switch (seltype) { case selectiontype.windowpolygon: result = acadpropers.editor.selectwindowpolygon(pnt3dcoll, fillist); break; case selectiontype.crossingpolygon: result = acadpropers.editor.selectcrossingpolygon(pnt3dcoll, fillist); break; case selectiontype.fence: result = acadpropers.editor.selectfence(pnt3dcoll, fillist); break; default: return null; } } catch (system.exception) { return null; } return ids; } /// <summary> /// 更具坐标选择对象,支持 /// windowpolygon 多边形内, crossingpolygon多边形相交, fence 线相交 /// </summary> /// <param name="seltype">选择类型</param> /// <param name="pnt3dcoll">坐标集</param> /// <returns></returns> public objectid[] ssget(selectiontype seltype, point3dcollection pnt3dcoll) { promptselectionresult result = null; objectid[] ids = null; try { switch (seltype) { case selectiontype.windowpolygon: result = acadpropers.editor.selectwindowpolygon(pnt3dcoll); break; case selectiontype.crossingpolygon: result = acadpropers.editor.selectcrossingpolygon(pnt3dcoll); break; case selectiontype.fence: result = acadpropers.editor.selectfence(pnt3dcoll); break; default: return null; } } catch (system.exception) { return null; } return ids; } /// <summary> /// 根据矩形框及过滤器,选择对象,支持 /// window 矩形框内, crossingwindow 矩形框相交 /// </summary> /// <param name="seltype">选择类型</param> /// <param name="pt1">矩形框点1</param> /// <param name="pt2">矩形框点2</param> /// <returns></returns> public objectid[] ssget(selectiontype seltype, point3d pt1, point3d pt2) { promptselectionresult result = null; objectid[] ids = null; try { switch (seltype) { case selectiontype.window: result = acadpropers.editor.selectwindow(pt1, pt2); break; case selectiontype.crossingwindow: result = acadpropers.editor.selectwindow(pt1, pt2); break; default: return null; } } catch (system.exception) { return null; } return ids; } /// <summary> /// 根据矩形框及过滤器,选择对象,支持 /// window 矩形框内, crossingwindow 矩形框相交 /// </summary> /// <param name="seltype">选择类型</param> /// <param name="pt1">矩形框点1</param> /// <param name="pt2">矩形框点2</param> /// <param name="fillist">过滤条件</param> /// <returns></returns> public objectid[] ssget(selectiontype seltype, point3d pt1, point3d pt2, selectionfilter fillist) { promptselectionresult result = null; objectid[] ids = null; try { switch (seltype) { case selectiontype.window: result = acadpropers.editor.selectwindow(pt1, pt2, fillist); break; case selectiontype.crossingwindow: result = acadpropers.editor.selectwindow(pt1, pt2, fillist); break; default: return null; } } catch (system.exception) { return null; } return ids; } 复制代码 代码写得不错!不过我不知道为什么一定要让c#的思维跟着lisp走! 这么复杂,直接p/invoke来的更简单 呵呵,支持,建议加精 哈哈,我是lisp转过来的习惯不一样啊比较喜欢lisp的ssget做选择集 很好 |
所有的时间均为北京时间。 现在的时间是 11:19 PM. |