I have a command that freezes a layer based on selected entity. If you are in a viewport, instead of freezing, the layer is VP freezed.
I have problem with layers from external reference. They appear VP frozen, but not in the Layer manager dialog and after saving and opening the drawing, they don't stay frozen.
If Not ed.CurrentViewportObjectId.IsNull Then
Dim oViewport As Viewport = trans.GetObject(ed.CurrentViewportObjectId, OpenMode.ForWrite, False)
oViewport.FreezeLayersInViewport(New ObjectIdCollection(New ObjectId() {layId}).GetEnumerator)