选择集过滤时的使用方式如下

转载自:http://www.cnblogs.com/jdmei520/articles/1326120.html

一、选择集过滤时的使用方式如下:

Object 指使用SelectionSet这个方法适用的对象

  1.  object.Select Mode[, Point1][, Point2][, FilterType][, FilterData] 
    
  2.  object.SelectOnScreen [FilterType][, FilterData] 
    
  3.  object.SelectAtPoint Point, FilterType, FilterData 
    

FilterType:Variant变体; 仅用于输入;(可选项) 指定使用的过滤器类型的 DXF 组码。

FilterData:Variant变体; 仅用于输入;(可选项) 过滤器的值。

二、DXF群组码共同群组码代码一览表

群码

说明

预设值

-4

过滤群组方式,例如 <AND、AND>、<OR、OR>、<XOR、XOR>、<NOT、NOT>

单一条件时可省略

-1

图元名称(会随每一个图档开启而有所不同)

不可省略

0

图元类型,例如 “ARC”、 “LINE”、“CIRCLE”…

不可省略

5

处理码

不可省略

6

线型名称(如果线型不为"BYLAYER",此群码值会出现)

BYLAYER

8

图层名称

不可省略

48

线性比例(选择性)

1.0

60

物件可见性, 0=可见, 1=不可见

0

62

颜色编号 (如果线型不为"BYLAYER",此群群码会出現)当值为0時,即指BYLAYER,如果是负值即指该图层是关闭的(选择性)

BYLAYER

67

值为空或0时即指图元在模型空间,如果为1指在图形空间

0

三、过滤群组方式

  • FilterType (DXF 群组码) = -4

过滤群组方式

內含项目

描述

运算法则

“<AND” … “AND>”

1 或 多个

所有项目的交集

1+1=1, 1+0=0, 0+1=0, 0+0=0

“<OR” … “OR>”

1 或多个

所有项目的并集

1+1=1, 1+0=1, 0+1=1, 0+0=0

“<XOR” … “XOR>”

2个

两个项目的异或运算

1+1=0, 1+0=1, 0+1=1, 0+0=0

“<NOT” … “NOT>”

1个

不包含此项目的值

NOT(1)=0,NOT(0)=1

四、范例:

1、过滤条件为图元为MTEXT

图元是MTEXT

FilterData

MTEXT

FilterType

0

2、过滤条件为图元为CIRCLE或LINE

图元是CIRCLE OR 图元是LINE

FilterData

<OR

CIRCLE

LINE

OR>

FilterType

-4

0

0

-4

3、过滤条件为图元在DIM 图层(LAYER)中的CIRCLE或LINE

(图元是CIRCLE OR 图元是LINE) AND 图层位于DIM层

FilterData

<AND

<OR

CIRCLE

LINE

OR>

DIM

AND>

FilterType

-4

-4

0

0

-4

8

-4

4、过滤的条件为图元为CIRCLE或LINE但图层(LAYER)不属于DIM层

(图元是CIRCLE OR 图元是LINE) AND NOT(图层位于DIM层)

FilterData

<AND

<OR

CIRCLE

LINE

OR>

<NOT

DIM

NOT>

AND>

FilterType

-4

-4

0

0

-4

-4

8

-4

-4

让我们看一个实例:我们想要选择层0上的所有直线和所有直径大于10的圆,该如何组合条件呢?

Let’s take a concrete example: let’s say we want to select all lines on on layer 0 and all the circles with radii greater than 10.'s how we would compose the conditions, in pseudo-code:

<or
<and
Layer == “0”
Entity type == “LINE”
and>
<and
Entity type == “CIRCLE”
Radius >= 10.0
and>
or>
转换为c#如下代码:为清楚起见,此处我把指定的属性/值以硬编码的形式实现,另如果需要应该直接由用户从数据库中进行选择。

This translates into the following C# code - for clarity I’ve left the specific properties/values hard-coded, but clearly it would be straightforward to ask the user or pick them out of a database, as needed.

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;

namespace EntitySelection
{
public class Commands
{
[CommandMethod(“SEWP”)]
public static void SelectEntitiesWithProperties()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;

         // Build a conditional filter list so that only
         // entities with the specified properties are
         // selected
         TypedValue[] tvs = new TypedValue[] 
          {
             new TypedValue((int)DxfCode.Operator, "<or"),
             new TypedValue((int)DxfCode.Operator, "<and"),
             new TypedValue((int)DxfCode.LayerName, "0"),
             new TypedValue((int)DxfCode.Start, "LINE"),
             new TypedValue((int)DxfCode.Operator, "and>"),
             new TypedValue((int)DxfCode.Operator, "<and"),
             new TypedValue((int)DxfCode.Start, "CIRCLE"),
             new TypedValue((int)DxfCode.Operator, ">="),
             new TypedValue((int)DxfCode.Real, 10.0),// Circle Radius
             new TypedValue((int)DxfCode.Operator, "and>"),
             new TypedValue((int)DxfCode.Operator, "or>")
         };

         SelectionFilter sf = new SelectionFilter(tvs);
         PromptSelectionResult psr = ed.SelectAll(sf);
         if (psr.Status == PromptStatus.OK)
          {
             SelectionSet SS = psr.Value;
             ObjectId[] idArray = SS.GetObjectIds();
             for (int i = 0; i < idArray.Length; i++)
              {
                 Entity ent = (Entity)Tools.GetDBObject(idArray[i]);
                 ent.Highlight();
                 Tools.WriteMessage(i + ":" + ent.ObjectId.ToString() + "," + ent.GetType().Name);
             }
         }

     }

 }//end class

}

--------------编辑于2019/6/2 -----------
看到有人回复说没有Tools,其实所谓的Tools就是一个自定义类文件,然后里面定义了WriteMessage方法。出自的是 曾洪飞 卢择临 张帆著的《AutoCAD VBA&VB.NET开发基础与实例教程(第2版)(C#版)》

    /// <summary>
    /// 在命令行输出信息
    /// </summary>
    /// <param name="ed">命令行对象</param>
    /// <param name="message">要输出的信息</param>
    public static void WriteMessage(this Editor ed, object message)
    {
        ed.WriteMessage(message.ToString());
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值