.NET

.NET

Reply
Mentor
mgorecki
Posts: 415
Registered: ‎09-23-2004
Message 1 of 21 (523 Views)

Viewport Layers Set To "Frozen" Are Still Visible

523 Views, 20 Replies
07-09-2012 11:36 AM

Hello,

I have a sub that gets a page number and a collection of layer ID's to freeze.  The sub will freeze the selected layers in all of the viewports except for the new one.

After running the program, the layers in the specific viewport are still visible, but when you go into Model mode in the viewport and check the layer status, it shows the selected layers are set to Freeze in the viewport. 

If I save the drawing, exit,and re-open it, the layers are now not visible.  I believe I have the "Regen" in the correct spot.

The code is attached.

    ' Freezes the selected layers in all other existing viewport layouts
    Public Sub freezeOtherLayouts(ByVal pageNumber As Integer, ByVal layersToFreezeLayerIds As ObjectIdCollection)
        Dim doc As Document = Application.DocumentManager.MdiActiveDocument
        Dim db As Database = doc.Database
        Dim ed As Editor = doc.Editor
        Dim detailLayer As String = "DETAIL_" & pageNumber
        Dim vp As Viewport = Nothing
        Dim viewPortFound As Boolean
        Dim vpIDs As ObjectIdCollection = Nothing
        Dim allLayerIDs As New ObjectIdCollection, detailLayerID As New ObjectIdCollection
        Dim freezeVPtrans As Transaction = Nothing

        Try
            freezeVPtrans = db.TransactionManager.StartTransaction()
            Dim myBT As BlockTable = db.BlockTableId.GetObject(OpenMode.ForRead)
            For Each btrID As ObjectId In myBT
                Dim myBTR As BlockTableRecord = btrID.GetObject(OpenMode.ForRead)
                ' If the block table record is a layout
                If myBTR.IsLayout Then
                    viewPortFound = False
                    If Not myBTR.Name = "*Model_Space" Then
                        Dim layOut As Layout = myBTR.LayoutId.GetObject(OpenMode.ForRead)
                        ' If the layout is the new layout
                        If layOut.TabOrder <> pageNumber Then
                            For Each id As ObjectId In myBTR
                                Dim obj As DBObject = id.GetObject(OpenMode.ForWrite)
                                ' If the object is a viewport (there is a model viewport which is found first, we want the second one)
                                If TypeOf obj Is Viewport And viewPortFound = True Then
                                    Dim vpref As Viewport = DirectCast(obj, Viewport)
                                    ' Selected Viewport for write.
                                    vp = freezeVPtrans.GetObject(vpref.ObjectId, OpenMode.ForWrite)
                                    Dim lt As LayerTable = freezeVPtrans.GetObject(db.LayerTableId, OpenMode.ForRead)
                                    ' Freeze the selected layers in the viewports
                                    vp.FreezeLayersInViewport(layersToFreezeLayerIds.GetEnumerator())
                                    lt.Dispose()
                                End If
                                If TypeOf obj Is Viewport Then
                                    viewPortFound = True
                                End If
                            Next
                        End If
                    End If
                End If
            Next
        Catch
            ed.WriteMessage("Error!")
        Finally
            freezeVPtrans.Commit()
            freezeVPtrans.Dispose()
            ed.Regen()
        End Try
    End Sub

 

Thanks,

Mark

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 2 of 21 (512 Views)

Re: Viewport Layers Set To "Frozen" Are Still Visible

07-09-2012 12:51 PM in reply to: mgorecki

Try add at the end of code:

 

ed.UpdateTiledViewportsInDatabase()

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Mentor
mgorecki
Posts: 415
Registered: ‎09-23-2004
Message 3 of 21 (503 Views)

Re: Viewport Layers Set To "Frozen" Are Still Visible

07-09-2012 01:47 PM in reply to: Hallex

I added that to the end of my program, but got an Unhandled Exception ({"eNotApplicable"}). 

Valued Mentor
jeff
Posts: 338
Registered: ‎05-12-2009
Message 4 of 21 (499 Views)

Re: Viewport Layers Set To "Frozen" Are Still Visible

07-09-2012 01:58 PM in reply to: mgorecki

Are you sure you not trying to set  on ViewPorts associated with Paperspace?

 

 

 

Might try iterating Database.GetViewports() passing in false.

 

Input flag indicating whether to return paperspace viewports associated with layouts 

 

You can also find your answers @ TheSwamp
Mentor
mgorecki
Posts: 415
Registered: ‎09-23-2004
Message 5 of 21 (497 Views)

Re: Viewport Layers Set To "Frozen" Are Still Visible

07-09-2012 02:07 PM in reply to: jeff

My viewport is in paperspace on layout P1 (I have Model, P1, and P2 layouts).  In order to see what layers are frozen in that particular viewport, I double picked in the viewport, which put me in Model mode.

Mentor
mgorecki
Posts: 415
Registered: ‎09-23-2004
Message 6 of 21 (481 Views)

Re: Viewport Layers Set To "Frozen" Are Still Visible

07-09-2012 03:37 PM in reply to: mgorecki

Hi Jeff,

Can you explain more in regards to "Might try iterating Database.GetViewports() passing in false".  I'm kinda new to VB.Net and I'm still learning.

 

Thanks,

Mark

Valued Mentor
jeff
Posts: 338
Registered: ‎05-12-2009
Message 7 of 21 (472 Views)

Re: Viewport Layers Set To "Frozen" Are Still Visible

07-09-2012 05:44 PM in reply to: mgorecki

This might work ok if your trying to not freeze the layers in new viewport and has never been Intialized, but would need to intialize any layouts that have never been.

 

 

        <CommandMethod("FreezeLayers")> _
        Public Sub MyGroupFreezeLayers() ' This method can have any name

            Dim doc As Document = Application.DocumentManager.MdiActiveDocument
            Dim db As Database = doc.Database
            Dim ed As Editor = doc.Editor

            Using trx As Transaction = db.TransactionManager.StartTransaction

                For Each id As ObjectId In db.GetViewports(False)

                    Dim vp As Viewport = id.GetObject(OpenMode.ForWrite)
                    vp.FreezeLayersInViewport(LayerIds(db).GetEnumerator)

                Next

                trx.Commit()
            End Using

        End Sub


        Private Function LayerIds(ByVal db As Database) As ObjectIdCollection

            Dim layIds As New ObjectIdCollection()
            layIds.Add(db.LayerZero)
            Return layIds

        End Function

 

 

You can also find your answers @ TheSwamp
Mentor
mgorecki
Posts: 415
Registered: ‎09-23-2004
Message 8 of 21 (451 Views)

Re: Viewport Layers Set To "Frozen" Are Still Visible

07-10-2012 03:18 PM in reply to: jeff

Hi Jeff,

I tried using your code but it didn't freeze the selected layer or any layers in the existing viewport in the P1 layout.  I'm still trying to understand the whole "db.GetViewports(False)" thing, maybe that's where my problem is.

Valued Mentor
jeff
Posts: 338
Registered: ‎05-12-2009
Message 9 of 21 (449 Views)

Re: Viewport Layers Set To "Frozen" Are Still Visible

07-10-2012 04:38 PM in reply to: mgorecki

That example should only freeze entites only on layer 0 and only in viewports that have been intialized.

You can also find your answers @ TheSwamp
Mentor
mgorecki
Posts: 415
Registered: ‎09-23-2004
Message 10 of 21 (431 Views)

Re: Viewport Layers Set To "Frozen" Are Still Visible

07-11-2012 03:21 PM in reply to: jeff

How do I initialize a layout?  Is it layout.initialize()  ?

 

I'm ready to post my entire program if it would help.  It's driving me crazy already.

I have only one layout in the drawing.  When the code runs, it adds a new layout to the drawing from a template.  A dialog pops up and asks which layers they want to see in the new layouts viewport.  It also asks which layers they do not want to see in all the other layouts viewports (because a new layer was added and if there are many more layouts it will freeze the selected layers in all the other viewports).  When the program is done running, the new layout looks great.  It shows the layers I want to see, but, the existing layout still looks lthe same.  The layers are all still visible, even though the layer manager says that the layers I told to freeze are frozen.  It's like it's just not finishing up and ending the last part. 

Here's the code that's supposed to freeze all the selected layers in all the other layouts viewports:

    ' Freezes the selected layers in all other existing viewport layouts
    Public Sub freezeOtherLayouts(ByVal pageNumber As Integer, ByVal layersToFreezeLayerIds As ObjectIdCollection)
        Dim doc As Document = Application.DocumentManager.MdiActiveDocument
        Dim db As Database = doc.Database
        Dim ed As Editor = doc.Editor
        Dim vp As Viewport = Nothing
        Dim viewPortFound As Boolean
        Dim freezeVPtrans As Transaction = db.TransactionManager.StartTransaction()

        Try
            Dim myBT As BlockTable = db.BlockTableId.GetObject(OpenMode.ForRead)
            For Each btrID As ObjectId In myBT
                Dim myBTR As BlockTableRecord = btrID.GetObject(OpenMode.ForRead)
                ' If the block table record is a layout
                If myBTR.IsLayout Then
                    viewPortFound = False
                    If Not myBTR.Name = "*Model_Space" Then
                        Dim layOut As Layout = myBTR.LayoutId.GetObject(OpenMode.ForRead)
                        ' If the layout is not the new layout
                        If layOut.TabOrder <> pageNumber Then
                            For Each id As ObjectId In myBTR
                                Dim obj As DBObject = id.GetObject(OpenMode.ForWrite)
                                ' If the object is a viewport (there is a model viewport which is found first, we want the second one)
                                If TypeOf obj Is Viewport And viewPortFound = True Then
                                    Dim vpref As Viewport = DirectCast(obj, Viewport)
                                    ' Selected Viewport for write.
                                    vp = freezeVPtrans.GetObject(vpref.ObjectId, OpenMode.ForWrite)
                                    Dim lt As LayerTable = freezeVPtrans.GetObject(db.LayerTableId, OpenMode.ForRead)
                                    ' Freeze the selected layers in the viewports
                                    vp.FreezeLayersInViewport(layersToFreezeLayerIds.GetEnumerator())
                                    ed.Regen()
                                    lt.Dispose()
                                End If
                                If TypeOf obj Is Viewport Then
                                    viewPortFound = True
                                End If
                            Next
                        End If
                    End If
                End If
            Next
        Catch
            ed.WriteMessage("Error!")
        Finally
            freezeVPtrans.Commit()
            freezeVPtrans.Dispose()
        End Try
    End Sub

 Help!

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.