马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
Block reference selection using selection filterBy Virupaksha Aithal
This example will prompt the user to select some entities and then filter all the block references named "ABC". It then iterates through the selection set and calls erase() method on each blockReference
- [CommandMethod("delABC")]
- public void delABC()
- {
- Document doc = Application.DocumentManager.MdiActiveDocument;
- Database db = doc.Database;
- Editor ed = doc.Editor;
- try
- {
- using (Transaction tr =
- db.TransactionManager.StartTransaction())
- {
- BlockTable BT =
- (BlockTable)tr.GetObject(db.BlockTableId,
- OpenMode.ForRead);
- TypedValue[] filterlist = new TypedValue[2];
- filterlist[0] = new TypedValue(0, "INSERT");
- filterlist[1] = new TypedValue(2, "ABC");
- SelectionFilter filter =
- new SelectionFilter(filterlist);
- PromptSelectionOptions opts =
- new PromptSelectionOptions();
- opts.MessageForAdding = "Select entities: ";
- PromptSelectionResult selRes =
- ed.GetSelection(opts, filter);
- if (selRes.Status != PromptStatus.OK)
- {
- ed.WriteMessage(
- "\nNo ABC block references selected");
- return;
- }
- if (selRes.Value.Count != 0)
- {
- SelectionSet set = selRes.Value;
- foreach (ObjectId id in set.GetObjectIds())
- {
- BlockReference oEnt =
- (BlockReference)tr.GetObject(id,
- OpenMode.ForWrite);
- oEnt.Erase();
- }
- }
- tr.Commit();
- }
- }
- catch (System.Exception ex)
- {
- ed.WriteMessage(ex.ToString());
- }
- }
|