This VB.NET example shows how to freeze or thaw a layer in a layout viewport using the FreezeLayersInViewport() and ThawLayersInViewport() methods. These methods take an ObjectIdCollection which is a collection of ObjectId for the layers to freeze or thaw.
By Wayne Brill
<CommandMethod("VPFreezeandThaw")> _
Public Sub VPFreezeandThaw()
Dim doc As Document = _
Application.DocumentManager.MdiActiveDocument
Dim ed As Editor = doc.Editor
Dim db As Database = doc.Database
Dim idLay As ObjectId
Dim idLayTblRcd As ObjectId
Dim lt As LayerTable
Dim tm As Autodesk.AutoCAD.ApplicationServices. _
TransactionManager = db.TransactionManager
Dim ta As Transaction = tm.StartTransaction()
Try
idLay = db.LayerTableId
lt = ta.GetObject(idLay, OpenMode.ForRead)
If lt.Has("wbtest") Then
idLayTblRcd = lt.Item("wbtest")
Else
ed.WriteMessage _
("Layer - wbtest not available")
Return
End If
Dim idCol As ObjectIdCollection = _
New ObjectIdCollection
idCol.Add(idLayTblRcd)
' Check that we are in paper space
Dim vpid As ObjectId = _
ed.CurrentViewportObjectId
If vpid.IsNull() Then
ed.WriteMessage("No Viewport current.")
Return
End If
'VP need to be open for write
Dim oViewport As Viewport = _
tm.GetObject(vpid, OpenMode.ForWrite)
If Not oViewport.IsLayerFrozenInViewport _
(idLayTblRcd) Then
oViewport.FreezeLayersInViewport _
(idCol.GetEnumerator())
Else
oViewport.ThawLayersInViewport _
(idCol.GetEnumerator())
End If
ta.Commit()
Finally
ta.Dispose()
End Try
End Sub