.NET

Reply
Active Contributor
ditran
Posts: 27
Registered: ‎01-28-2013
Message 1 of 5 (218 Views)
Accepted Solution

Turn on/off Viewport Error

218 Views, 4 Replies
05-13-2013 08:48 PM

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.

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

Distinguished Mentor
gasty1001
Posts: 582
Registered: ‎04-11-2010
Message 2 of 5 (209 Views)

Re: Turn on/off Viewport Error

05-13-2013 09:43 PM in reply to: ditran

Hi,

 

Do those TryCast really return something?

 

Gaston Nunez

Active Contributor
ditran
Posts: 27
Registered: ‎01-28-2013
Message 3 of 5 (198 Views)

Re: Turn on/off Viewport Error

05-14-2013 01:10 AM in reply to: ditran

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

Active Contributor
ditran
Posts: 27
Registered: ‎01-28-2013
Message 4 of 5 (162 Views)

Re: Turn on/off Viewport Error

05-15-2013 10:23 PM in reply to: ditran

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

 

Thanks for any help.

Active Contributor
xdbk07
Posts: 42
Registered: ‎11-06-2012
Message 5 of 5 (142 Views)

Re: Turn on/off Viewport Error

05-17-2013 04:18 AM in reply to: ditran

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

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.