@tim.turner wrote:
Now in 2022 it freezes the layer in all model space.
That is how the program behaves based on this condition
(if (= pLayer cLayer)
(command "_.layer" "_s" "0" "_off" pLayer "")
(command "_.vplayer" "_f" pLayer "_c" "")
)
If current layer is the same as the layer name from the selected object. The code invokes "_Layer" command and set the current to "0" and follow up with "_off" while still in "_Layer" command
What you can do is this, only set the layer to "0" if the selected objects layer name matches the curent one and immediately step out of the IF statement, leaving the call to _Vplayer to be freeze the selected layer.
(defun c:VF ( / ent cLayer pLayer)
(setq ent (car(entsel "\nSelect object to VP-freeze layer: ")))
(setq cLayer (getvar "clayer"))
(setq pLayer (cdr (assoc 8 (entget ent))))
(if (= pLayer cLayer)
(command "_.layer" "_s" "0" "")
)
(command "_.vplayer" "_f" pLayer "_c" "")
(prompt (strcat "Layer " pLayer " frozen in current viewport"))
(princ)
)
HTH