KRBeckman Posted February 23, 2010 Share Posted February 23, 2010 I think I've seen this before, but I can't seem to find it. I just need a lisp that will delete everything in the current open drawing that's on a particular layer, even if the entities are in a block. Thanks a ton!! Quote Link to comment Share on other sites More sharing options...
alanjt Posted February 23, 2010 Share Posted February 23, 2010 Not sure if I posted it here, but here it is at theswamp.org http://www.theswamp.org/index.php?topic=30675.0 Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted February 23, 2010 Share Posted February 23, 2010 Not sure if this would work? (defun c:DeleteAll (/ ent layer i ss ent) (vl-load-com) (cond ( (setq ent (car (nentsel "\nSelect Object on Layer to Delete: "))) (setq layer (cdr (assoc 8 (entget ent)))) (setq i -1 ss (ssget "_X" (list (cons 8 layer)))) (while (setq ent (ssname ss (setq i (1+ i)))) (entdel ent)) (vlax-for blks (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-acad-object))) (vlax-for obj blks (if (eq (strcase layer) (strcase (vla-get-layer obj))) (vla-delete obj)))))) (princ)) Quote Link to comment Share on other sites More sharing options...
alanjt Posted February 23, 2010 Share Posted February 23, 2010 You could also just use the LayDel command. Quote Link to comment Share on other sites More sharing options...
KRBeckman Posted February 23, 2010 Author Share Posted February 23, 2010 Not sure if this would work? (defun c:DeleteAll (/ ent layer i ss ent) (vl-load-com) (cond ( (setq ent (car (nentsel "\nSelect Object on Layer to Delete: "))) (setq layer (cdr (assoc 8 (entget ent)))) (setq i -1 ss (ssget "_X" (list (cons 8 layer)))) (while (setq ent (ssname ss (setq i (1+ i)))) (entdel ent)) (vlax-for blks (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-acad-object))) (vlax-for obj blks (if (eq (strcase layer) (strcase (vla-get-layer obj))) (vla-delete obj)))))) (princ)) How would I change this to delete everything on layer "Blah"... I would rather not have to select the layer, cause it will be the same layer everytime, and the objects that I'm deleting are some of a blocks attributes and don't show up in the drawing. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted February 23, 2010 Share Posted February 23, 2010 Perhaps: (defun c:DeleteAll (/ *error* LAYER UFLAG) (vl-load-com) ;; Lee Mac ~ 23.02.10 (defun *error* (msg) (and UFlag (vla-EndUndoMark *doc)) (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **"))) (princ)) (setq layer "Blah") (setq *doc (cond (*doc) ((vla-get-ActiveDocument (vlax-get-acad-object))))) (if (and (tblsearch "LAYER" layer) (eq :vlax-false (vla-get-lock (vla-item (vla-get-Layers *doc) layer)))) (progn (setq uFlag (not (vla-StartUndoMark *doc))) (vlax-for lay (vla-get-Layouts *doc) (vlax-for obj (vla-get-Block lay) (if (eq (strcase layer) (strcase (vla-get-layer obj))) (vl-catch-all-apply (function vla-delete) (list obj))))) (vlax-for blk (vla-get-Blocks *doc) (vlax-for obj blk (if (eq (strcase layer) (strcase (vla-get-layer obj))) (vl-catch-all-apply (function vla-delete) (list obj))))) (setq uFlag (vla-EndUndomark *doc))) (princ "\n** Layer Locked or Not Found **")) (princ)) Quote Link to comment Share on other sites More sharing options...
KRBeckman Posted February 23, 2010 Author Share Posted February 23, 2010 Perhaps: (defun c:DeleteAll (/ *error* LAYER UFLAG) (vl-load-com) ;; Lee Mac ~ 23.02.10 (defun *error* (msg) (and UFlag (vla-EndUndoMark *doc)) (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **"))) (princ)) (setq layer "Blah") (setq *doc (cond (*doc) ((vla-get-ActiveDocument (vlax-get-acad-object))))) (if (and (tblsearch "LAYER" layer) (eq :vlax-false (vla-get-lock (vla-item (vla-get-Layers *doc) layer)))) (progn (setq uFlag (not (vla-StartUndoMark *doc))) (vlax-for lay (vla-get-Layouts *doc) (vlax-for obj (vla-get-Block lay) (if (eq (strcase layer) (strcase (vla-get-layer obj))) (vl-catch-all-apply (function vla-delete) (list obj))))) (vlax-for blk (vla-get-Blocks *doc) (vlax-for obj blk (if (eq (strcase layer) (strcase (vla-get-layer obj))) (vl-catch-all-apply (function vla-delete) (list obj))))) (setq uFlag (vla-EndUndomark *doc))) (princ "\n** Layer Locked or Not Found **")) (princ)) Tried it and I get one problem... it automattically runs when I open an old drawing or start a new drawing... and I need it to be executed through a command. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted February 23, 2010 Share Posted February 23, 2010 Tried it and I get one problem... it automattically runs when I open an old drawing or start a new drawing... and I need it to be executed through a command. Doesn't for me Quote Link to comment Share on other sites More sharing options...
alanjt Posted February 23, 2010 Share Posted February 23, 2010 If it's loading automatically, then you have something calling it. Lee's code will only run if called. Lee, I haven't seen this before (setq uFlag (not (vla-StartUndoMark *doc))) That's an interesting idea. Yours? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted February 23, 2010 Share Posted February 23, 2010 Lee, I haven't seen this before (setq uFlag (not (vla-StartUndoMark *doc))) That's an interesting idea. Yours? Mine indeed I use the same construct for writing to files: (defun *error* (msg) (and ofile (close ofile)) ... (princ)) (setq ofile (open "... ")) (setq ofile (close ofile)) Quote Link to comment Share on other sites More sharing options...
alanjt Posted February 23, 2010 Share Posted February 23, 2010 Mine indeed I use the same construct for writing to files: (defun *error* (msg) (and ofile (close ofile)) ... (princ)) (setq ofile (open "... ")) (setq ofile (close ofile)) Yeah, that one's a given. The undo flag is interesting though. I just have it check to make sure the activedoc is defined and then execute undo end. I like. I've done the same thing for resetting a UCS to world and back. Just create a flag if it has to be changed, then it's there when the program exits. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted February 23, 2010 Share Posted February 23, 2010 Yeah, that one's a given.The undo flag is interesting though. I just have it check to make sure the activedoc is defined and then execute undo end. I like. I've done the same thing for resetting a UCS to world and back. Just create a flag if it has to be changed, then it's there when the program exits. Yeah, I just do it to append the Undo Loop, otherwise things go a bit skewey.. Quote Link to comment Share on other sites More sharing options...
alanjt Posted February 23, 2010 Share Posted February 23, 2010 Yeah, I just do it to append the Undo Loop, otherwise things go a bit skewey.. Makes sense. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted February 23, 2010 Share Posted February 23, 2010 I wonder if Ms Beckman got it working after all this chitter chatter... Quote Link to comment Share on other sites More sharing options...
KRBeckman Posted February 23, 2010 Author Share Posted February 23, 2010 Doesn't for me Yep, got it. Thanks again!! Mine indeed I use the same construct for writing to files: (defun *error* (msg) (and ofile (close ofile)) ... (princ)) (setq ofile (open "... ")) (setq ofile (close ofile)) Lee, you need to start making some money doings this... Wait no, then I wouldn't get anything done. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted February 23, 2010 Share Posted February 23, 2010 Lee, you need to start making some money doings this... Wait no, then I wouldn't get anything done. Yeah, I wish, but not too many people would pay - as it is so accessible. Quote Link to comment Share on other sites More sharing options...
KRBeckman Posted February 23, 2010 Author Share Posted February 23, 2010 I wonder if Ms Beckman got it working after all this chitter chatter... Hey Man... its Mr. Beckman rofl Quote Link to comment Share on other sites More sharing options...
alanjt Posted February 23, 2010 Share Posted February 23, 2010 Hey Man... its Mr. Beckman rofl Gender typo. Quote Link to comment Share on other sites More sharing options...
KRBeckman Posted February 23, 2010 Author Share Posted February 23, 2010 Yeah, but it would have just been wierd to let that go on too long. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted February 23, 2010 Share Posted February 23, 2010 Oops! 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.