Lee Mac Posted April 4, 2009 Posted April 4, 2009 Hi Guys, This piece of code came from another thread (quite recently), but, as it was slightly off-topic, I thought it deserved a new thread. I originally posted this code to move all entities from layer "0" to layer "0-From0", but it kept showing an error, and I couldn't work out why: (defun c:0to0 (/ ss layers 0lay 0Nlay err) (if (setq ss (ssget "X" '((8 . "0")))) (progn (setq layers (vla-get-layers (vla-get-ActiveDocument (vlax-get-acad-object)))) (vlax-for lay layers (cond ((eq "0" (vla-get-name lay)) (setq 0lay lay)) ((eq "0-From0" (vla-get-name lay)) (setq 0Nlay lay)))) (if (not 0Nlay) (setq 0Nlay (vla-add layers "0-From0"))) (vla-put-color 0Nlay (vla-get-color 0lay)) (vla-put-linetype 0Nlay (vla-get-linetype 0lay)) (vla-put-lineweight 0Nlay (vla-get-lineweight 0lay)) (if (vl-catch-all-error-p (setq err (vl-catch-all-apply '(lambda (x) (vla-put-layer x "0-From0")) (mapcar 'vlax-ename->vla-object (mapcar 'cadr (ssnamex ss)))))) (princ (strcat "\nError: " (vl-catch-all-error-message err))))) (princ "\n<!> No Objects Found on Layer \"0\" <!>")) (princ)) I resorted to posting this piece of code, just to get me by, but the original is driving me up the wall, as I can't work out the source of the error! (defun c:0to0 (/ ss layers 0lay 0Nlay) (if (setq ss (ssget "X" '((8 . "0")))) (progn (setq layers (vla-get-layers (vla-get-ActiveDocument (vlax-get-acad-object)))) (vlax-for lay layers (cond ((eq "0" (vla-get-name lay)) (setq 0lay lay)) ((eq "0-From0" (vla-get-name lay)) (setq 0Nlay lay)))) (if (not 0Nlay) (setq 0Nlay (vla-add layers "0-From0"))) (vla-put-color 0Nlay (vla-get-color 0lay)) (vla-put-linetype 0Nlay (vla-get-linetype 0lay)) (vla-put-lineweight 0Nlay (vla-get-lineweight 0lay)) (mapcar '(lambda (x) (vla-put-layer x "0-From0")) (mapcar 'vlax-ename->vla-object (mapcar 'cadr (ssnamex ss))))) (princ "\n<!> No Objects Found on Layer \"0\" <!>")) (princ)) Your help and time is much appreciated! Cheers Lee Quote
wizman Posted April 4, 2009 Posted April 4, 2009 you're missing one mapcar lee, in place of vl-catch-all-apply (setq err (vl-catch-all-apply '(lambda (x) (vla-put-layer x "0-From0")) (mapcar 'vlax-ename->vla-object (mapcar 'cadr (ssnamex ss)))))) i think there is no need to catch error since youre only dealing with one layer which is layer 0. if it is locked(layer 0) then all will not be processed. you need to unlock layer 0 in the beginning since transferring from layer 0 to the other layer is your target. Quote
Lee Mac Posted April 5, 2009 Author Posted April 5, 2009 Thanks Wizman - But even if I wanted to use this error trapping method - I thought that vl-catch-all-apply performed in the same manner as "mapcar", am I wrong? And yes, maybe I should include coding to unlock layer 0 if locked. Cheers Lee Quote
wizman Posted April 5, 2009 Posted April 5, 2009 But even if I wanted to use this error trapping method - I thought that vl-catch-all-apply performed in the same manner as "mapcar", am I wrong? it functions much more like 'APPLY' function. You'll see it when you wrote it in its other form. (mapcar '(lambda (x) (if (vl-catch-all-error-p (setq err (vl-catch-all-apply 'vla-put-layer (list x "0-From0") ) ) ) (princ (strcat "\nError: " (vl-catch-all-error-message err) ) ) ) ) (mapcar 'vlax-ename->vla-object (mapcar 'cadr (ssnamex ss)) ) ) Quote
Lee Mac Posted April 5, 2009 Author Posted April 5, 2009 Ahh, I see now - clue is in the name I suppose Cheers Wizman as always Lee Quote
leos98 Posted April 5, 2009 Posted April 5, 2009 Hello Lee, I saw this thread and I'm glad you were able to figure out the error with the code. I also would like to ask you about unlocking layer zero. Can you post in my other thread a revise code that will unlock layer zero before moving all entities from it? Thanks! Quote
Lee Mac Posted April 5, 2009 Author Posted April 5, 2009 Hello Lee,I saw this thread and I'm glad you were able to figure out the error with the code. I also would like to ask you about unlocking layer zero. Can you post in my other thread a revise code that will unlock layer zero before moving all entities from it? Thanks! No Problem Leos - Will do Quote
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.