C#.NET里面怎样实现多重过滤选择?
例如选择“0"层半径大于40的圆,或者选择“0”层文字高度等于5的所有文字等等之类。 是不是问题太简单了,居然没有人回应。没办法自己摸索吧,终于弄出来了,呵呵,同lisp语言有点儿类似。不敢独享,对还有疑问的人可能会有帮助。功能:选择半径大于等于40,小于100的所有圆和0层、1层上的所有线(*LINE)。
lisp代码:
(setq ss (ssget '((-4 . "=")
(40 . 40)
(-4 . "")
(-4 . "")
(-4 . "OR>")
)
)
)C#代码:
using System;
using System.Collections.Generic;
using System.Text;// 访问AutoCAD程序对象。
using Autodesk.AutoCAD.ApplicationServices;// 访问 the AutoCAD 编辑器。
using Autodesk.AutoCAD.EditorInput;// 命令注册。
using Autodesk.AutoCAD.Runtime;// 访问数据库对象。
using Autodesk.AutoCAD.DatabaseServices;namespace Prompt
{
public class Class1
{
static public void SelectEnt()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
PromptSelectionOptions selectionOp = new PromptSelectionOptions();
// 多重选择,选择半径大于等于40的圆或者0,1层上的所有线
TypedValue[] filList =
{
new TypedValue(-4,"="),
new TypedValue(40,40),
new TypedValue(-4,""),
new TypedValue(-4,""),
new TypedValue(-4,"OR>")
};//注意分号
SelectionFilter filter = new SelectionFilter(filList);
PromptSelectionResult ssRes = ed.GetSelection(selectionOp, filter);
if (ssRes.Status == PromptStatus.OK)
{
SelectionSet SS = ssRes.Value;
int nCount = SS.Count;
ed.WriteMessage("选择了{0}个实体", nCount);
}
}
}
} 请问你的AutoCAD是什么版本? 跟版本有关系吗?我用的是Autocad 2009. 据我了解,你的代码至少在2006,2007版本里是不行的,和语法无关,应该是SelectionFilter里的bug;
比如同样的方式,实现选取半径为40的圆是可以的,但实现选取半径为40的圆和圆弧是不可以的,选取图层A的直线和圆也是不可以的.
那你给搞成可以在2006,2007,2009版本都可运行的
都是些强人!!! function XML() {
} 2006的SelectionFilter中有BUG?以前好像在2006中使用过多重选择,没遇到问题啊? 回复
我用的就是2006,是否可以提供一下相关代码,想要过滤选择所有长度大于210的LWPOLYLINE,用楼主的代码一直调试不过,谢了先~~~
页:
[1]