(setq Locked_Layers (cons item Locked_Layers)) ; set variable "locked_layers" to all locked layers.
(vlax-put-property item "Lock" :vlax-false) ; unlock each layer if it is locked.
) ; end progn
) ; end if
) ; end vlax
;; Copy to layer
(if (setq ss (ssget "_:L"))
(command "._-copytolayer" ss "")
) ; end if
; If any layers were locked at the beginning, lock them again. -https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/unlocking-layers-is-painfully-slow/m-p/2881866#M294136
(if Locked_Layers
(mapcar '(lambda (x) (vlax-put-property x "Lock" :vlax-true)) Locked_Layers)