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
Hello Virupaksha,
Thank you for your interest in this, but as for my issue, it was finally cleared up by downloading the latest service pack. Unfortunately for others using 2013, it still seems to be a problem.
Best regards,
Mark
Maybe this topic is old, but I face the same problem.
Solution is nice, but isn't there a more 'elegant' (read: efficient) way to do this?
Activating the layouts isn't really necessary, cause when i run program, save and close drawing and reopend it the visibility-problem is solved and correct. So activating is more something like a workaround and doesn't really attack the issue.
Guess Hallex's solution attempts to do this, BUT, I got same problem as everybody else here: Unhandled Exception {"eNotApplicable"}.
so.. wonder if maybe today there are some new insights?
I don't see anything strange when freezing Vp Layers.
The Vp freezes the Layers without any required refreshes (AutoCAD 2019 and later).
Attached is a rather lengthily (C#) sample building a Layout from scratch.
Use it on a drawing containing layers named *VpFreeze*