ObjectArx 发表于 2017-5-27 08:25:01

(获取实体ID集合时)过滤器的使用及检测(过滤器引用)对象的类型名称

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>")               
               };
                SelectionFilterxfilter= 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>")               
               };
                SelectionFilterxfilter= new SelectionFilter(ftv);
    (3)其它如 (A和B)或者(C和D)的,模式为:
                   "<OR"

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

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

                  "OR>"

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



      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.ObjectId;
                }
                return o1;
            }
      }




SHUNDocker 发表于 2021-4-27 09:14:31

感谢楼主分享学习!!!

随便点 发表于 2022-12-9 21:13:14

谢谢分享                     
页: [1]
查看完整版本: (获取实体ID集合时)过滤器的使用及检测(过滤器引用)对象的类型名称