在使用.NET开发AutoCAD时,获取的选择集可以用SelectionFilter对象进行过滤,这样用户就可以只选择对自己操作有用的实体了。关于这个SelectionFilter选择过滤器,偶以前只知道用DxfCode.Start组码来过滤单种类形的实体(如直线、圆、圆弧等)。今天在才鸟兄的指点下,找到了几个多重选择CAD实体的方法,现总结如下:
只过滤直线实体
PromptSelectionOptions CurOption
= new PromptSelectionOptions();
CurOption.SingleOnly = false;
CurOption.AllowDuplicates = false;
CurOption.MessageForAdding = "<Ben>请选择曲线:";
TypedValue[] filList = new TypedValue[]{
new TypedValue((int)DxfCode.Start,"LINE")
};//只过滤直线
SelectionFilter filter = new SelectionFilter(filList);
PromptSelectionResult ssr
= ed.GetSelection(CurOption, filter);
同时过滤直线、圆和圆弧
PromptSelectionOptions CurOption
= new PromptSelectionOptions();
CurOption.SingleOnly = false;
CurOption.AllowDuplicates = false;
CurOption.MessageForAdding = "<Ben>请选择曲线:";
TypedValue[] filList = new TypedValue[]{
new TypedValue((int)DxfCode.Start,"LINE,ARC,CIRCLE")
};//同时过滤直线、圆和圆弧
SelectionFilter filter = new SelectionFilter(filList);
PromptSelectionResult ssr
= ed.GetSelection(CurOption, filter);
过滤所有曲线
PromptSelectionOptions CurOption
= new PromptSelectionOptions();
CurOption.SingleOnly = false;
CurOption.AllowDuplicates = false;
CurOption.MessageForAdding = "<Ben>请选择曲线:";
TypedValue[] filList = new TypedValue[]{
new TypedValue((int)DxfCode.Subclass,"CURVE")
};//过滤所有曲线
SelectionFilter filter = new SelectionFilter(filList);
PromptSelectionResult ssr
= ed.GetSelection(CurOption, filter);
过滤0层上的所有曲线
PromptSelectionOptions CurOption
= new PromptSelectionOptions();
CurOption.SingleOnly = false;
CurOption.AllowDuplicates = false;
CurOption.MessageForAdding = "<Ben>请选择曲线:";
TypedValue[] filList = new TypedValue[]{
new TypedValue((int)DxfCode.Subclass,"CURVE"),
new TypedValue((int)DxfCode.LayerName,"0")
};//过滤0层上的所有曲线
SelectionFilter filter = new SelectionFilter(filList);
PromptSelectionResult ssr
= ed.GetSelection(CurOption, filter);