Hunter Posted March 2, 2009 Share Posted March 2, 2009 thanks~ When deleting layers from layer manager, I have to delete all objects on it first(I use CAD 2006)...so, I'm a lazy guy:P 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? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 2, 2009 Share Posted March 2, 2009 Try this: (defun DeleteLayer (Name / ss) (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"))) (defun c:Ldel (/ dcTag lst uClk) (vl-load-com) (setq dcTag (load_dialog "laydel.dcl")) (if (not (new_dialog "laydel" dcTag)) (progn (alert "The Dialog Box could not be loaded.") (exit))) (start_list "lays" 3) (mapcar 'add_list (setq lst (vl-remove-if '(lambda (x) (or (eq x "0") (eq x (getvar "CLAYER")))) (laylist)))) (end_list) (action_tile "accept" "(setq lay (nth (atoi (get_tile \"lays\")) lst) uClk T) (done_dialog)") (action_tile "cancel" "(setq uClk nil) (done_dialog)") (start_dialog) (unload_dialog dcTag) (if uClk (DeleteLayer lay)) (princ)) (defun laylist (/ oLst) (vlax-for l (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object))) (setq oLst (cons (vla-get-Name l) oLst))) (reverse oLst)) laydel.zip Quote Link to comment Share on other sites More sharing options...
Hunter Posted March 2, 2009 Share Posted March 2, 2009 Thanks Lee~ It works perfectly~ How nice u are! Quote Link to comment Share on other sites More sharing options...
rocheey Posted March 2, 2009 Share Posted March 2, 2009 For a programming exercise in LISP, note that a layer can be deleted with a simple one-liner: (vl-catch-all-apply 'vla-Delete (list (vlax-ename->vla-object (tblobjname "LAYER" "layername")))) And it can with VBA, as well: ThisDrawing.Layers.Item("layername").Delete It's less code, and runs faster. But the original version is much more robust. As for accounting for layer zero (or the current later), I just would not place them in the listbox to begin with. I'd leave the layer deleting code in the layer deleting sub, and account for data filtering to the sub, from the user Interface. BTW. Nice code, Hunter:roll: Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 2, 2009 Share Posted March 2, 2009 As for accounting for layer zero (or the current later), I just would not place them in the listbox to begin with. I'd leave the layer deleting code in the layer deleting sub, and account for data filtering to the sub, from the user Interface. I remove the layer "0" and the current layer from the layer list before populating the popup_list in the dialog box. Removing the need for the extra "if" statement at the start of the layer deletion code. 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.