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