.NET

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

Turn on/off Viewport Error

208 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.

Valued Mentor
gasty1001
Posts: 477
Registered: ‎04-11-2010
Message 2 of 5 (199 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 (188 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 (152 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 (132 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?

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.