One way to identify the un- initialized layout is check the number of viewports in the layout. If the number of viewports are greater than 0, then layout is initialized. Refer below sample code
[CommandMethod("Testlayout")]
public static void Testlayout()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
using (Transaction Tx = db.TransactionManager.StartTransaction())
{
DBDictionary dic = Tx.GetObject(db.LayoutDictionaryId,
OpenMode.ForRead) as DBDictionary;
Layout layout = null;
foreach (DBDictionaryEntry entry in dic)
{
layout = Tx.GetObject(entry.Value,
OpenMode.ForRead) as Layout;
if (!layout.ModelType)
{
ObjectIdCollection ids = layout.GetViewports();
if (ids.Count == 0)
{
ed.WriteMessage(layout.LayoutName +
" is not initializedn");
}
else
{
ed.WriteMessage(layout.LayoutName +
" is initializedn");
}
}
}
Tx.Commit();
}
}

Leave a Reply