see here:
http://www.cadtutor.net/forum/showthread.php?t=33191 Hi,Lee~
Is this a subroutine ?
Would u please tell me how to run it directly?
Thanks ~
Hi Hunter,
Yes, it is a sub-function, and requires one argument - namely the layer name.
Something like this:
(defun DeleteLayer(Name / layCol dLay oVal) (vl-load-com) (if (and (/= Name "0") (/= (strcase Name) (getvar "CLAYER"))) (progn (setq layCol (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object)))) (if (vl-catch-all-error-p (setq dLay (vl-catch-all-apply 'vla-Item (list layCol (strcat Name))))) (princ "\nLayer does not exist! ") (if (vl-catch-all-error-p (vl-catch-all-apply 'vla-Delete (list dLay))) (princ "\nCan't delete layer in use! ") (setq oVal T)))) (princ "\nCan't delete active layer or layer \"0\"! ")) oVal)(defun c:test (/ lay) (setq lay (getstring "\nType Name of Layer...")) (DeleteLayer lay) (princ)) I suppose you could also include coding to delete everything on that layer before deleting the layer...
(defun DeleteLayer(Name / layCol dLay oVal) (vl-load-com) (if (and (/= Name "0") (/= (strcase Name) (getvar "CLAYER"))) (progn (setq layCol (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object)))) (if (vl-catch-all-error-p (setq dLay (vl-catch-all-apply 'vla-Item (list layCol (strcat Name))))) (princ "\nLayer does not exist! ") (if (vl-catch-all-error-p (vl-catch-all-apply 'vla-Delete (list dLay))) (princ "\nCan't delete layer in use! ") (setq oVal T)))) (princ "\nCan't delete active layer or layer \"0\"! ")) oVal)(defun c:test (/ lay ss) (setq lay (getstring "\nType Name of Layer...")) (setq ss (mapcar 'cadr (ssnamex (ssget "X" (list (cons 8 lay)))))) (mapcar 'entdel ss) (DeleteLayer lay) (princ)) Excuse my last post, doesn't allow for an empty selection set... may return error lseltp nil. You could compress the code into this:
(defun DeleteLayer(Name / ss) (vl-load-com) (if (and (/= Name "0") (tblsearch "LAYER" Name) (/= (strcase Name) (getvar "CLAYER"))) (progn (if (setq ss (ssget "X" (list (cons 8 lay)))) (mapcar 'entdel (mapcar 'cadr (ssnamex ss)))) (if (vl-catch-all-error-p (vl-catch-all-apply 'vla-Delete (list (vlax-ename->vla-object (tblobjname "LAYER" Name))))) (princ "\nError Deleting Layer"))) (princ "\nLayer not found or Current Layer or Layer \"0\"")))(defun c:test (/ lay) (setq lay (getstring "\nSpecify Layer to Delete...")) (DeleteLayer lay) (princ)) Hi, Lee:
Thanks for your kindly reply~
It's really appreciated! No Problems Hunter, did my last code function properly? Yeah, it works fine~
And it would be perfect if there would be a dialogue box to selecte the layers:)
Haha, you love your Dialog Boxes
I could create one for it, but, tbh, isn't this the same as just going into the layer manager and deleting the layer from there?
页:
1
[2]