- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,my question is like this.
Inserting sidedb into the current drawing will import many useless blocks, anonymous blocks, etc
I want to precisely purge all of these now,
but I need to keep all the blocks before inserting action.
I have some code, but it will purge all the blocks.
I see a method
Public void Purge (ObjectidGraph idGraph);
But I don't know how to use it to achieve my goal.
public static void PurgeBlock(this Database db)
{
string sLine = db.OriginalFileName;
using (var tr = db.TransactionManager.StartTransaction())
{
try
{
#region 块
var bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
ObjectIdCollection idsBt;
do
{
idsBt = new ObjectIdCollection(bt.Cast<ObjectId>().ToArray());
db.Purge(idsBt);
foreach (ObjectId id in idsBt)
{
tr.GetObject(id, OpenMode.ForWrite).Erase();
}
} while (0 < idsBt.Count);
#endregion 块
}
catch (SystemException ex1)
{
string message = string.Format("错误名称:【{0}】\nStackTrace:【{1}】\n:TargetSite【{2}】\n【{3}】",
ex1.Message, ex1.StackTrace.ToString(), ex1.TargetSite.ToString(), sLine);
TestHelper.AddError(message);
}
catch (Runtime.Exception ex2)
{
string message = string.Format("错误名称:【{0}】\nStackTrace:【{1}】\n:TargetSite【{2}】,【{3}】",
ex2.Message, ex2.StackTrace.ToString(), ex2.TargetSite.ToString(), sLine);
TestHelper.AddError(message);
}
tr.Commit();
}
}
Solved! Go to Solution.