(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;
}
}