Community
I would like to create a command that locks all the viewports in a drawing file. I would like to navigate the ViewportTable as it seems the most efficient, but it does not look like the ViewportTableRecord contains this property.
If I am cycling through the ViewportTable, how do I get to the Viewport properties of a ViewportTableRecord?
Shared Sub LockAllViewports() Dim myDoc As Document = Application.DocumentManager.MdiActiveDocument Dim myDB As Database = myDoc.Database Using myTrans As Transaction = myDB.TransactionManager.StartTransaction Dim myViewportTable As ViewportTable myViewportTable = myTrans.GetObject(myDB.ViewportTableId, OpenMode.ForRead) For Each acObjectID As ObjectId In myViewportTable Dim myViewport As DatabaseServices.Viewport myViewport = myTrans.GetObject(acObjectID, OpenMode.ForWrite) myViewport.Locked = True Next End Using End Sub
Thank you for any guidance.
Mike Killion
Take a look at Database.GetViewports(false)
want to pass in false since you do not paperspace viewport.
This will not work for a new drawing until the layouts are activated
<CommandMethod("ChangeLockAllViewports")> _ Shared Sub ChangeLockAllViewports() Dim myDoc As Document = Application.DocumentManager.MdiActiveDocument Dim myDB As Database = myDoc.Database Using myTrans As Transaction = myDB.TransactionManager.StartTransaction Dim veiwportIds As ObjectIdCollection = myDB.GetViewports(False) For Each acObjectID As ObjectId In veiwportIds Dim myViewport As Viewport = myTrans.GetObject(acObjectID, OpenMode.ForWrite) myViewport.Locked = Not myViewport.Locked Next myTrans.Commit() End Using End Sub