.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Viewports v. ViewportTableRecords

1 REPLY 1
Reply
Message 1 of 2
mikekillion
645 Views, 1 Reply

Viewports v. ViewportTableRecords

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

1 REPLY 1
Message 2 of 2
jeff
in reply to: mikekillion

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

 

 

You can also find your answers @ TheSwamp

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost