The frozen layers for a given pvport are stored in the entity as xdata, under the "ACAD" app name. The code is 1003 /int/ and the value is the layer name /string/. For some reason i can't remove an entry from the xdata. I can only add new entries /add other layers to be frozen/. I'm not sure if i am missing something, or it isn't possible at all.
Here is the code i came up with. Have a look at it. It works for other entities containing xdata, but not for pvports. If you find out why it isn't working, please let me know.
(defun c:test (/ LM:RemoveOnce doc layerName layoutName codes vals arrPos codeArr valArr codeLst varLst)
;;--------------------=={ Remove Once }==---------------------;;
;; ;;
;; Removes the first occurrence of an item from a list ;;
;;------------------------------------------------------------;;
;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;;
;;------------------------------------------------------------;;
;; Arguments: ;;
;; x - item to be removed ;;
;; l - list from which to remove first occurrence of item ;;
;;------------------------------------------------------------;;
;; Returns: Resultant list following the removal ;;
;;------------------------------------------------------------;;
(defun LM:RemoveOnce ( x l / f )
(setq f equal)
(vl-remove-if '(lambda ( a ) (if (f a x) (setq f (lambda ( a b ) nil)))) l)
);defun
(setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
(setq layerName "A1" layoutName "FP5")
(if (and (tblsearch "layer" layerName) (vl-position layoutName (layoutlist)))
(progn
(vlax-for item (vla-get-Block (vla-Item (vla-get-Layouts doc) layoutName))
(if (= (vla-get-ObjectName item) "AcDbViewport")
(progn
;This is the part of the function that doesn't work on pvport entities.
;Get the pvport's xdata
(vla-getxdata item "ACAD" 'codes 'vals)
;if the pvport has xdata and the layer name is present in the xdata,
;record the layer's position in the array, in the var "arrPos"
(if (and codes vals (setq arrPos (vl-position layerName (mapcar 'variant-value (vlax-safearray->list vals)))))
(progn
;Create an empty array for the xdata codes, that is 1 item shorter than the original
(setq codeArr (vlax-make-safearray vlax-vbInteger (cons 1 (- (length (vlax-safearray->list codes)) 1))))
;Create an empty array for the xdata values, that is 1 item shorter than the original
(setq valArr (vlax-make-safearray vlax-vbVariant (cons 1 (- (length (vlax-safearray->list vals)) 1))))
;Create lists with the layer information removed from them /1 item shorter than the original xdata/
(setq codeLst (LM:RemoveOnce (nth arrPos (vlax-safearray->list codes)) (vlax-safearray->list codes)))
(setq varLst (LM:RemoveOnce (nth arrPos (vlax-safearray->list vals)) (vlax-safearray->list vals)))
;Fill the newly created arrays with the code and data lists
(vlax-safearray-fill codeArr codeLst)
(vlax-safearray-fill valArr varLst)
;Set the xdata for the object
(vla-SetXData item codeArr valArr)
));if xdata
));if vp
);vlax-for
));if layer and layout
(princ)
);defun