3dwannab Posted July 21, 2022 Share Posted July 21, 2022 I want to be able to copy a locked layer to a new one with the COPYTOLAYER command. I've tried to get around this by unlocking the layers before, then after the COPYTOLAYER command. This will throw an error like so when I try to copy a locked layer: Here's the code: (vl-load-com) ;; PROBLEM ;; AutoCAD gives unhandled exception error with eOnLockedLayer. ;; TO ADD ;; Change this to have undo handling (defun c:Lay_Copy_Locked (/ layUlist laydata ss) (setq doc (vla-get-ActiveDocument (vlax-get-Acad-Object))) ; Unlock all layers - https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/unlocking-layers-is-painfully-slow/m-p/2881866#M294136 (vlax-for item (vla-get-layers doc) (if (= (vlax-get-property item "Lock") :vlax-true) (progn (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) ) ; end if (princ) ) ; defun (c:Lay_Copy_Locked) Quote Link to comment Share on other sites More sharing options...
marko_ribar Posted July 21, 2022 Share Posted July 21, 2022 (defun c:Lay_Copy_Locked ( / *error* layUlist laydata ss ) (vl-load-com) (defun *error* ( m ) (if command-s (command-s "_.UNDO" "_E") (vl-cmdf "_.UNDO" "_E") ) (if m (prompt m) ) (princ) ) (setq doc (vla-get-ActiveDocument (vlax-get-Acad-Object))) (if (= 8 (logand 8 (getvar 'undoctl))) (if command-s (command-s "_.UNDO" "_E") (vl-cmdf "_.UNDO" "_E") ) ) (if command-s (command-s "_.UNDO" "_G") (vl-cmdf "_.UNDO" "_G") ) ; Unlock all layers - https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/unlocking-layers-is-painfully-slow/m-p/2881866#M294136 (vlax-for item (vla-get-layers doc) (if (= (vlax-get-property item "Lock") :vlax-true) (progn (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) ) ; end if (*error* nil) ) ; defun 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.