- [CommandMethod("tt")]
- public static void Test()
- {
- Database db = HostApplicationServices.WorkingDatabase;
- Document doc = Application.DocumentManager.GetDocument(db);
- Editor ed = doc.Editor;
- PromptResult resName = ed.GetString("\n请输入块名:");
- if (resName.Status != PromptStatus.OK)
- return;
- using (Transaction tr = db.TransactionManager.StartTransaction())
- {
- BlockTableRecord btr = db.CurrentSpaceId.GetObject(OpenMode.ForRead) as BlockTableRecord;
- Layout layout = btr.LayoutId.GetObject(OpenMode.ForRead) as Layout;
- SelectionFilter filter =
- new SelectionFilter
- (
- new TypedValue[]
- {
- new TypedValue(0, "Insert"),
- new TypedValue(2, resName.StringResult),
- new TypedValue(410, layout.LayoutName),
- }
- );
- var resSel = ed.SelectAll(filter);
- if (resSel.Status != PromptStatus.OK)
- return;
- int i = 0;
- foreach (ObjectId id in resSel.Value.GetObjectIds())
- {
- BlockReference blkref = id.GetObject(OpenMode.ForRead) as BlockReference;
- ed.WriteMessage("\n找到第{0}个,基点:{1}", ++i, blkref.Position);
- }
- }
- }
|