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

Turn on/off Viewport Error

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
ditran
517 Views, 4 Replies

Turn on/off Viewport Error

Hi All,

 

Please let me know this error:

 

1.png

 

When I try the code:

 

Public Sub HVP()
        Dim doc As Document = Application.DocumentManager.MdiActiveDocument
        Dim ed As Editor = doc.Editor
        Dim db As Database = HostApplicationServices.WorkingDatabase
        Using DocLock As DocumentLock = Application.DocumentManager.MdiActiveDocument.LockDocument()
            Using tr As Transaction = db.TransactionManager.StartTransaction()
                Try
                    Dim layoutdict As DBDictionary = TryCast(tr.GetObject(db.LayoutDictionaryId, OpenMode.ForRead, False, True), DBDictionary)
                    For Each entry As DBDictionaryEntry In layoutdict
                        If entry.Key <> "Model" Then
                            Dim lay As Layout = TryCast(tr.GetObject(entry.Value, OpenMode.ForRead, False, True), Layout)
                            For Each vpid As ObjectId In lay.GetViewports()
                                Dim vp As Autodesk.AutoCAD.DatabaseServices.Viewport = TryCast(tr.GetObject(vpid, OpenMode.ForWrite, True, True), Autodesk.AutoCAD.DatabaseServices.Viewport)

                                    vp.On = False

                            Next
                        End If
                    Next
                Catch ex As Exception
                    MsgBox(ex.Message & ex.StackTrace & ex.ErrorStatus)
                End Try
                tr.Commit()
            End Using
        End Using

 

Thanks for any help.

4 REPLIES 4
Message 2 of 5
hgasty1001
in reply to: ditran

Hi,

 

Do those TryCast really return something?

 

Gaston Nunez

Message 3 of 5
ditran
in reply to: ditran

I try to use "DirectCast" but the result will be the same.

Message 4 of 5
ditran
in reply to: ditran

I there any way to turn off/on all objects in each layout ?

 

Thanks for any help.

Message 5 of 5
ditran7577
in reply to: ditran

It OK if we turn on all viewport (vp.on=true). What happpen?

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