Now I do know that one wouldn't and shouldn't work in modelspace through a viewport, and think full coverage of tiled viewports is a good thing. Having this too in the paperspace viewport I find still irritating; I don't think there's a way around it.
Of course there's a way around it! That's what the last parameter of Autodesk.AutoCAD.GraphicsInterface.TransientManager.AddTransient is for:
an IntegerCollection for the passing of viewport numbers. Example in F#:
let viewports = new IntegerCollection()
let setViewports() =
let db = acApp.DocumentManager.MdiActiveDocument.Database
let tilemode =
acApp.GetSystemVariable "TILEMODE" |> unbox<int16> = 1s
let inPaperspace =
acApp.GetSystemVariable "CVPORT" |> unbox<int16> = 1s
// do nothing when in modelspace
if tilemode then ()
// paperspace viewport only when in paperspace
elif inPaperspace then viewports.Add 1 |> ignore
// add all except paperspace viewport when floating
else
use tr = db.TransactionManager.StartTransaction()
for vpId in db.GetViewports false do
let vp = tr.GetObject(vpId, OpenMode.ForRead) :?> Viewport
viewports.Add vp.Number |> ignore
tr.Commit()
The idea is to generate the viewport numbers only when really necessary; that is in a floating viewport; the other cases are trivial. I hope they make sense: all viewports (default) when in modelspace, paperspace viewport only when in paperspace.
All the best, Thorsten
PS Do you read me, Norman?
PPS [Edited] Nice try. CVPORT = 1 for paperspace is right.
http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%20.NET%20Developer%27s%20Guide, Define Layouts and Plot > Viewports > Floating Viewports is wrong.