The event for switching layouts is your best bet.
When you handle then event,
open the BlockTableRecord defined by the LayoutEventArgs.ID property
If you look at the name of the BlockTable record it will be either *Model_Space or *Paper_Space.
Interestingly enough, BlockTableRecord.ModelSpace is a static string that you could you to compare to, but for some reason, whenever I use it in code, AutoCAD crashes.
Well, I here is some code that was written to be added to the EventsWatcher Sample.
C
[code]
private void callback_LayoutSwitched(object sender, LayoutEventArgs e)
{
WriteLine(String.Format("LayoutSwitched - {0}", e.Name));
Autodesk.AutoCAD.ApplicationServices.TransactionManager tm = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.TransactionManager;
Transaction tr = tm.StartTransaction();
try
{
DBObject dbO = tr.GetObject(e.Id, OpenMode.ForRead);
if (dbO is BlockTableRecord)
{
BlockTableRecord btr = (BlockTableRecord)dbO;
bool isModel = false;
isModel =(string.Compare(btr.Name.ToUpper , "*MODEL_SPACE"))==0;
WriteLine(String.Format("IsModelSpace - {0}", isModel));
}
tr.Commit();
}
catch (System.Exception ex)
{
tr.Abort ();
}
finally
{
tm.Dispose();
}
}
[/code]