Here's a little code. The first viewport is always the paperspace viewport.
You could cycle through the viewports by size or scale etc to choose a particular one
LayoutManager lm = LayoutManager.Current;
Layout layout = tr.GetObject(lm.GetLayoutId(lm.CurrentLayout), OpenMode.ForRead) as Layout;
ObjectIdCollection vpIds = layout.GetViewports();
if (vpIds.Count < 2)
{
MessageBox.Show("There are no viewports in this layout, exiting:");
return;
}
if (db.PaperSpaceVportId == ed.CurrentViewportObjectId)// in paperspace viewport
{
if (vpIds.Count == 2)
{
vp = tr.GetObject(vpIds[1], OpenMode.ForWrite) as Viewport;
vp.Locked = false;
ed.SwitchToModelSpace();
}
else