C#练习遍历块,删除块内指定名称的块
net模块总帖子比较少,正在练习,分享一下//查找图块并删除
public void Mydeltk()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
PromptStringOptions pStrOpts = new PromptStringOptions("\nEnter your name: ");
pStrOpts.AllowSpaces = true;
PromptResult pStrRes = ed.GetString(pStrOpts);
if (pStrRes.Status != PromptStatus.OK) return;
Application.ShowAlertDialog("The name entered was: " +
pStrRes.StringResult);
String Blockname = pStrRes.StringResult;
//定义过滤器
TypedValue[] filList = new TypedValue;
filList = new TypedValue(0, "Insert");
//filList = new TypedValue(2, br.Name);
SelectionFilter filter = new SelectionFilter(filList);
//选择对象
PromptSelectionResult res = ed.SelectAll(filter);
if(res.Status != PromptStatus.OK) return;
Transaction trans = db.TransactionManager.StartTransaction();
using (trans)
{
try
{
//
//遍历选择集
foreach (ObjectId id in res.Value.GetObjectIds())
{
BlockReference Selent = (BlockReference)trans.GetObject(id, OpenMode.ForWrite);
// BlockReference br = ent as BlockReference;
// Selent.Color = Color.FromColorIndex(ColorMethod.ByLayer, 256);
DelBlockSubEntity(ed, trans, Selent, Blockname);
}
//ed.WriteMessage("\n一共查找了" + res.Value.Count );
trans.Commit();
}
catch (Autodesk..Runtime.Exception e)
{
// Something went wrong
ed.WriteMessage(e.ToString());
}
}
}
**** Hidden Message *****}
页:
[1]