EaBIM一直以来积极响应国家“十二五”推进建筑业信息化的号召,对建筑领域的信息技术开展深入技术交流和探讨!致力于打造“BIM-建筑师-生态技术”三位一体综合资源交流共享平台,希望为BIM与可持续设计理念及技术的普及做出微小的贡献!!!

EaBIM

 找回密码
 注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

搜索
查看: 1204|回复: 10
打印 上一主题 下一主题

[实体对象] 有条件选择AutoCAD实体

[复制链接]

1514

主题

7465

帖子

1万

积分

admin

Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10

积分
12408

社区QQ达人

跳转到指定楼层
楼主
发表于 2014-1-8 16:19:09 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
如何更好的选择多个层中的实体:AutoCAD的选择过滤机理使得这个选择起来实现起来很容易,同时还能实现跟实体的各个属性相关的复合性选择。
This post was inspired by a comment on this previous post, where we looked at some code to select entities on a specific layer. The question was regarding how best to select entities from multiple layers: the selection filtering mechanism inside AutoCAD makes this very easy, and can cope with composition of conditions related to various entity properties.
基本的思路就是添加你所想要过滤的实体特性的标签,标签标明了过滤条件:条件"or",添加"<or"与">or";条件"and",添加"<and"与">and"。
The basic concept is to enclose sets of entity properties for which you wish to filter with tags indicating the composition of the conditions: for "or" you enclose the conditions with "<or" and "or>" and for "and" you use "<and" and "and>". Wow: I can safely say that that's probably the only sentence I've ever written that has 6 of the last 10 words being "and". :-)
让我们看一个实例:我们想要选择层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);
                    ent.Highlight();
                    Tools.WriteMessage(i + ":" + ent.ObjectId.ToString() + "," + ent.GetType().Name);
                }
            }
        }
    }//end class
}

另外,你也可以使用"<xor"与"xor>"进行一个高级"or"选择的测试。
By the way - you can also choose to perform an "exclusive or" test by using "<xor" and "xor>".
To try out this code, draw a number of lines in a blank drawing, and run the SEWP command. This simply tells you how many entities met the selection criteria - it doesn't leave them selected for use by further commands. You can then see how drawing circles of varying radii changes the number of entities selected by the command.
On a final note... SelectionFilters can be used either non-interactively (as in this example, via the SelectAll() method) or interactively (via GetSelection(), SelectWindow(), SelectCrossingPolygon(), SelectFence(), etc.). I've shown simple uses of SelectionFilters in previous posts, but it's also possible to use quite complicated groupings of conditions - as we've scratched the surface of in this post.

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
收藏收藏 转播转播 分享分享 分享淘帖 支持支持 反对反对

相关帖子

工作时间:工作日的9:00-12:00/13:30-18:00,节假日不在线,请勿留言

8

主题

792

帖子

1349

积分

BIM经理

Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6

积分
1349
3F
发表于 2014-5-22 15:44:01 | 只看该作者
路过!!! 不发表意见……

14

主题

867

帖子

1439

积分

BIM经理

Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6

积分
1439
7F
发表于 2014-6-11 18:14:42 | 只看该作者
顶...... 楼下跟上.....

28

主题

763

帖子

1425

积分

BIM经理

Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6

积分
1425
8F
发表于 2014-6-13 14:15:33 | 只看该作者
顶......
楼下跟上.....

15

主题

899

帖子

1462

积分

BIM经理

Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6

积分
1462
11F
发表于 2014-6-13 14:35:53 | 只看该作者
顶......
楼下跟上.....
*滑块验证:
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|EaBIM网 ( 苏ICP备2020058923号-1  苏公网安备32011502011255号

GMT+8, 2024-11-30 18:04

Powered by Discuz! X3.2 Licensed

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表