objectarx.net 过滤集

1.过滤器常用操作符组合
   (1)  a或b
            操作符:"<OR"     "a"   "b"     "OR>"

            例集合包含 多断线(对像类型名称为LWPOLYLINE) 或 块参照(对像类型名称为INSERT)

               TypedValue[] ftv = new TypedValue[]
                  {        
                new TypedValue((int)DxfCode.Operator , "<OR"),            
                new TypedValue((int)DxfCode.Start, "LWPOLYLINE") ,                     
                new TypedValue((int)DxfCode.Start, "INSERT"),            
                new TypedValue((int)DxfCode.Operator , "OR>")               
                 };
                SelectionFilter  xfilter= new SelectionFilter(ftv);

    (2)   a和b
            操作符:"<AND"     "a"   "b"     "AND>"

            例: 在“ping"层的直线。(是直线并且所在层名称为“ping“)
               TypedValue[] ftv = new TypedValue[]
                  {        
                new TypedValue((int)DxfCode.Operator , "<AND"),            
                new TypedValue((int)DxfCode.Start, "LINE") ,                     
                new TypedValue((int)DxfCode.LayerName, "ping"),            
                new TypedValue((int)DxfCode.Operator , "AND>")               
                 };
                SelectionFilter  xfilter= new SelectionFilter(ftv);
    (3)其它如 (A和B)或者(C和D)的,模式为:
                   "<OR"

                   "<AND"
                    “ A”
                    “ B ”         
                   "AND>"

                    "<AND"
                    “ C”
                    “ D ”         
                   "AND>"

                    "OR>"

2.在使用过滤器过滤指定对象时,需要设置对象类型名称,如参照块“INSERT”,多段线“LWPOLYLINE”
   不知DXFNAME时可以如下做测试来获取

  [CommandMethod("getentsdxfanme", CommandFlags.Session)]
        public void getentsdxfanme()
        {
            using (DocumentLock docLock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument())
            {
                ObjectId obt = GetSelectFirstEntityid();
                if (!obt.IsNull)
                {
                    Database db = HostApplicationServices.WorkingDatabase;
                    using (Transaction trans = db.TransactionManager.StartTransaction())
                    {
                        Entity ent = (Entity)trans.GetObject(obt , OpenMode.ForWrite);                       
                        ed.WriteMessage(ent.GetRXClass().DxfName .ToString () );                       
                        trans.Commit();
                    }
                }
            }
           
     }


public static ObjectId GetSelectFirstEntityid() //通过鼠标获取单个实体ID
        {
            using (DocumentLock docLock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument())
            {
                Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
                Database db = HostApplicationServices.WorkingDatabase;                
           ObjectId o1 = new ObjectId();
                PromptSelectionOptions selectionOp = new PromptSelectionOptions();                
                PromptSelectionResult ssRes = ed.GetSelection(selectionOp);
                if (ssRes.Status == PromptStatus.OK)
                {
                    o1 = ssRes.Value[0].ObjectId;
                }
                return o1;
            }
        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值