Delete all layouts
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all,
i would like to delete all layouts. I tested these two method.
I have problem with LayoutManager becuase delete is very slow.
If DWG is complex and has for example 20 pages it toos lots of time (because function still swap page by page).
This second method is much more fastert but i will getting error if i delete all pages (even if i before created one which i jump over).
i know that layer manager delete all dependencies but is there any way how to delete all old layouts faster?
(in second method my plan was call purge function after that)
private static bool DeleteAllLayouts()
{
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Editor ed = acDoc.Editor;
using (DocumentLock LockDoc = acDoc.LockDocument())
{
using (Database db = acDoc.Database)
{
// metode 1
using (Transaction tr = db.TransactionManager.StartTransaction())
{
using (DBDictionary layoutDict = (DBDictionary)db.LayoutDictionaryId.GetObject(OpenMode.ForWrite))
{
LayoutManager acLayoutMgr = LayoutManager.Current;
acLayoutMgr.CreateLayout("LayoutXX");
foreach (DBDictionaryEntry entry in layoutDict)
{
string layoutName = entry.Key.ToUpper();
if (layoutName != "MODEL" && layoutName != "LAYOUTXX")
{
acLayoutMgr.DeleteLayout(layoutName);
}
}
acLayoutMgr.RenameLayout("LayoutXX", "Layout1");
acLayoutMgr.CurrentLayout = "Model";
tr.Commit();
acLayoutMgr.Dispose();
}
}
// metode 2
using (Transaction tr = db.TransactionManager.StartTransaction())
{
DBDictionary layoutsEx = tr.GetObject(db.LayoutDictionaryId, OpenMode.ForRead) as DBDictionary;
BlockTable blkTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
using (BlockTableRecord blkBlkRec = new BlockTableRecord())
{
int layoutCount = layoutsEx.Count - 1;
blkBlkRec.Name = "*Paper_Space" + layoutCount.ToString();
blkTbl.Add(blkBlkRec);
tr.AddNewlyCreatedDBObject(blkBlkRec, true);
DBDictionary layouts = tr.GetObject(db.LayoutDictionaryId, OpenMode.ForWrite) as DBDictionary;
using (Layout lay = new Layout())
{
lay.LayoutName = "LayoutXX";
lay.AddToLayoutDictionary(db, blkBlkRec.ObjectId);
tr.AddNewlyCreatedDBObject(lay, true);
}
}
tr.Commit();
}
using (Transaction tr = db.TransactionManager.StartTransaction())
{
using (DBDictionary layoutDict = tr.GetObject(db.LayoutDictionaryId, OpenMode.ForRead) as DBDictionary)
{
foreach (DBDictionaryEntry de in layoutDict)
{
Layout layout = (Layout)tr.GetObject(de.Value, OpenMode.ForWrite);
string layoutName = de.Key;
if (layoutName != "Model" && layoutName != "LayoutXX")
{
layout.Erase();
}
}
tr.Commit();
ed.Regen();
}
}
}
}
return true;
}
...
Link copied