GregGleason Posted April 25, 2018 Share Posted April 25, 2018 This is a simple "delete these layers" lisp program. I get drawings where I have to delete layers that are not on an approved list. So I just figure out what the unapproved layers are, make sure they don't have objects and are not frozen, then run the lisp to delete them. It seems to works ok. Is this the way to do it? Here is the code: (defun C:DelLayers () (setvar 'CMDECHO 0) (command "_.-layer" "_T" "0" "_ON" "0" "_S" "0" "") ; ----------------------------------------------- (command "_PURGE" "_LAY" "_11-2605G1K-1-24" "_NO") (command "_PURGE" "_LAY" "_11-2606G1K-1-24" "_NO") (command "_PURGE" "_LAY" "_11-2607G1K-1-24" "_NO") (command "_PURGE" "_LAY" "_11-2608G1K-1-24" "_NO") (command "_PURGE" "_LAY" "_G1K-1" "_NO") ; ----------------------------------------------- (setvar 'CMDECHO cmdecho) ) Greg Quote Link to comment Share on other sites More sharing options...
rkmcswain Posted April 25, 2018 Share Posted April 25, 2018 Looks good to me. You could purge them all on one line using commas if you like. You might explore using the LAYDEL command, if you don't care about the entities on those layers. It will delete them and the layer. LAYMRG can delete the layer and move the objects to another layer first. Quote Link to comment Share on other sites More sharing options...
ronjonp Posted April 25, 2018 Share Posted April 25, 2018 You could give this a try too: (defun c:dellayers (/ e) (foreach layer '("_11-2605G1K-1-24" "_11-2606G1K-1-24" "_11-2607G1K-1-24" "_11-2608G1K-1-24") (if (setq e (tblobjname "layer" layer)) (vl-catch-all-apply 'vla-delete (list (vlax-ename->vla-object e))) ) ) (princ) ) I'm surprised that your code works .. it should fail here: (setvar 'CMDECHO cmdecho) since 'cmdecho' is never set?? Perhaps you have a global set from somewhere else. Quote Link to comment Share on other sites More sharing options...
GregGleason Posted April 25, 2018 Author Share Posted April 25, 2018 You could give this a try too: (defun c:dellayers (/ e) (foreach layer '("_11-2605G1K-1-24" "_11-2606G1K-1-24" "_11-2607G1K-1-24" "_11-2608G1K-1-24") (if (setq e (tblobjname "layer" layer)) (vl-catch-all-apply 'vla-delete (list (vlax-ename->vla-object e))) ) ) (princ) ) I'm surprised that your code works .. it should fail here: (setvar 'CMDECHO cmdecho) since 'cmdecho' is never set?? Perhaps you have a global set from somewhere else. Hmmmm... well that explains the error. I'll comment it out and see what it should be set to. Your code looks interesting in that I think I might be able to use a file to read the approved layers and then take out all the ones not on the list. Thanks! Greg Quote Link to comment Share on other sites More sharing options...
ronjonp Posted April 25, 2018 Share Posted April 25, 2018 Hmmmm... well that explains the error. I'll comment it out and see what it should be set to. Your code looks interesting in that I think I might be able to use a file to read the approved layers and then take out all the ones not on the list. Thanks! Greg This is what you should do for resetting your variable: (defun c:dellayers (/ cmd) (setq cmd (getvar 'cmdecho)) (setvar 'cmdecho 0) ;; Code ... (setvar 'cmdecho cmd) ) Quote Link to comment Share on other sites More sharing options...
GregGleason Posted April 26, 2018 Author Share Posted April 26, 2018 Thanks ronjonp! Fixing the code now. Greg 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.