CAD二次开发之选择集过滤
一、选择集过滤时的使用方式如下:
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>、、OR>、、XOR>、、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
过滤群组方式 |
內含项目 |
描述 |
运算法则 |
"" |
1 或 多个 |
所有项目的交集 |
1+1=1, 1+0=0, 0+1=0, 0+0=0 |
"" |
1 或多个 |
所有项目的并集 |
1+1=1, 1+0=1, 0+1=1, 0+0=0 |
"" |
2个 |
两个项目的异或运算 |
1+1=0, 1+0=1, 0+1=1, 0+0=0 |
"" |
1个 |
不包含此项目的值 |
NOT(1)=0,NOT(0)=1 |
四、范例:
1、过滤条件为图元为MTEXT
图元是MTEXT
FilterData |
MTEXT |
FilterType |
0 |
2、过滤条件为图元为CIRCLE或LINE
图元是CIRCLE OR 图元是LINE
FilterData |
CIRCLE |
LINE |
OR> |
|
FilterType |
-4 |
0 |
0 |
-4 |
3、过滤条件为图元在DIM 图层(LAYER)中的CIRCLE或LINE
(图元是CIRCLE OR 图元是LINE) AND 图层位于DIM层
FilterData |
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 |
CIRCLE |
LINE |
OR> |
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:
·
·
· Layer == "0"
· Entity type == "LINE"
· 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, "),
new TypedValue((int)DxfCode.Operator, "),
new TypedValue((int)DxfCode.LayerName, "0"),
new TypedValue((int)DxfCode.Start, "LINE"),
new TypedValue((int)DxfCode.Operator, "and>"),
new TypedValue((int)DxfCode.Operator, "),
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
}
CAD二次开发之选择集过滤相关推荐
- CAD二次开发清除选择集
ed.SetImpliedSelection(new ObjectId[] { });
- c# cad二次开发 通过选择txt文件将自动转换成多段线
c# cad二次开发 通过选择txt文件将自动转换成多段线,txt样式如下 using System; using System.Collections.Generic; using System.T ...
- C#之CAD二次开发(10) 用户交互之选择集
# 0. 前言 CAD中通过用户交互来选择对象,也可以通过.NET API模拟不同对象选择选项. 当执行多个选择集时,可以创建一个ObjectIdCollection对象来跟踪已选择的对象. 可以用如 ...
- CAD中的选择集过滤----有条件选择AutoCAD实体
转载自:http://www.cnblogs.com/jdmei520/articles/1326120.html 一.选择集过滤时的使用方式如下: Object 指使用SelectionSet这个方 ...
- cad怎么选择一个对象打散vba_CADVBA中的选择集过滤.doc
CAD中的选择集过滤 一.选择集过滤时的使用方式如下: Object 指使用SelectionSet这个方法适用的对象 1)????? object.Select Mode[, Point1][, P ...
- CAD二次开发(C#) 第一节
前言 由于工作需要,最近在学习二次开发,将其记录于此,以便日后查看. 语法 涉及"特性","进程"知识点,需要有所了解 #region CAD二次开发--第一节 ...
- CAD 二次开发 图层操作(3)取得指定图层下的所有对象id
对于CAD二次开发的人来说,可能需要对某一图层下的实体(点,线,面域,块,三维实体)进行不同的操作.下面的方法,即可实现获取指定图层名称下的所有实体ID. 输入参数为图层名称: 返回值为:对象主键集合 ...
- c# CAD二次开发 模拟CAD移动图形, 通过圆现在注记,改变图形颜色
c# CAD二次开发 模拟CAD移动图形, 通过圆现在注记,改变图形颜色 using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD ...
- lisp CAD二次开发 宗地线自动编号
lisp CAD二次开发 宗地线自动编号 (defun c:ZZ () (setvar "osmode" 0) (princ "\n选取宗地线-") (setq ...
最新文章
- NoSQL生态系统——事务机制,行锁,LSM,缓存多次写操作,RWN
- mybatis中 Executor的设计与实现
- keilcjson内存分配失败_iOS标准库中常用数据结构和算法之内存池
- 当你老了,一生最后悔什么?大数据告诉你!
- signature=095ed28e83b68620637b3a67436b0f8f,SMB 3.1.1 Encryption in Windows 10
- Linus 07年在 Google讲座介绍Git的特点和设计思路
- how to reference the parent form from the WPF control(Control in ElementHost)
- FE.ES-理解Event Loop
- 微软MCITP系列课程(二四)利用组策略部署软件
- (一)GPS与基站定位
- 解决word生成目录-页码-字体问题
- 5G NR 调度、帧结构相关
- 面试被问扔鸡蛋问题:100层扔鸡蛋问题(扔球问题)
- intellij idea 工具栏的隐藏和显示
- pyqt5 时间控件设为当前日期
- 文人和书生 摘自《明朝那些事儿》
- html中鱼眼效果,鱼眼效果和放大效果怎么做
- 《计算机网络自顶向下方法》读书笔记(一)
- 【毕业季·进击的技术er】忆毕业一年有感
- 参加SAP培训是否有用?