/// <summary>
/// 获取窗口中块说明
/// </summary>
/// <param name="db">数据库对象</param>
/// <param name="pt1">窗口选择角点1</param>
/// <param name="pt2">窗口选择角点2</param>
/// <returns></returns>
public static void getBlocks(this Database db,Point3d pt1,Point3d pt2)
{
BlockTableRecord btr = new BlockTableRecord();
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.GetDocument(db).Editor;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
//选取模型空间中指定窗口中的块
var blocks = from d in db.SelectCrossingWindow<BlockReference>(pt1,pt2)
select d;
foreach (var bref in blocks)
{
btr =(BlockTableRecord) trans.GetObject(bref.BlockTableRecord, OpenMode.ForRead);
ed.WriteMessage("\n块名为:"+ bref.Name + "\n块说明为:" + btr.Comments);
}
trans.Commit();
}
}
/// <summary>
/// 选择窗口中及和窗口四条边界相交的实体,实体类型为T
/// </summary>
/// <typeparam name="T">实体的类型</typeparam>
/// <param name="db">数据库对象</param>
/// <param name="pt1">窗口的一个角点</param>
/// <param name="pt2">窗口的另一个角点</param>
/// <returns>返回类型为T的实体</returns>
public static List<T> SelectCrossingWindow<T>(this Database db, Point3d pt1, Point3d pt2) where T : Entity
{
return SelectCrossingWindow<T>(db, pt1, pt2, OpenMode.ForRead, false);
}
/// <summary>
/// 选择窗口中及和窗口四条边界相交的实体,实体类型为T
/// </summary>
/// <typeparam name="T">实体的类型</typeparam>
/// <param name="db">数据库对象</param>
/// <param name="pt1">窗口的一个角</param>
/// <param name="pt2">窗口的另一个角点</param>
/// <param name="mode">实体的打开方式</param>
/// <param name="openErased">是否打开已删除的实体</param>
/// <returns>返回类型为T的实体</returns>
public static List<T> SelectCrossingWindow<T>(this Database db, Point3d pt1, Point3d pt2, OpenMode mode, bool openErased) where T : Entity
{
var trans = db.TransactionManager;
string dxfname = RXClass.GetClass(typeof(T)).DxfName;
List<T> ents = new List<T>();
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
TypedValue[] values = { new TypedValue((int)DxfCode.Start, dxfname) };
var filter = new SelectionFilter(values);
var entSelected = ed.SelectCrossingWindow(pt1, pt2, filter);
if (entSelected.Status == PromptStatus.OK)
{
foreach (var id in entSelected.Value.GetObjectIds())
{
T t = (T)(object)trans.GetObject(id, mode, openErased);
ents.Add(t);
}
}
return ents;
}
通过LINQ和窗口来选择块参照,并且获取块的说明