AdamW Posted October 5, 2018 Posted October 5, 2018 Lee Mac posted this code in response to another user that wanted to delete everything on a layer including items within a block (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)) After reading Lee Mac's tutorial on ssget filters I thought I would change the filter ssget "_X" (all) to ssget "_B" (window) so that you can just delete everything within a window that you select. However if you draw an object around blocks It says no objects found. Is this because It can not find the objects within the blocks or in correct use of the "_B" filter or perhaps incorrect understanding of the code. Quote
Tharwat Posted October 5, 2018 Posted October 5, 2018 (edited) Hi, Just replace the string mode "_X" with this "_:L" which would allow you to use the window selection along with filter to avoid selecting objects that are reside on locked layer. NOTE: I recommend to add some codes to check if the selected object resides on a locked layer, then just alert a message to the user and exit the program quietly without processing. So if you followed the above note then just remove the string mode "_X" and that would be enough. Edited October 5, 2018 by Tharwat 1 Quote
Lee Mac Posted October 5, 2018 Posted October 5, 2018 (edited) 13 hours ago, AdamW said: After reading Lee Mac's tutorial on ssget filters I thought I would change the filter ssget "_X" (all) to ssget "_B" (window) so that you can just delete everything within a window that you select. However if you draw an object around blocks It says no objects found. Is this because It can not find the objects within the blocks or in correct use of the "_B" filter or perhaps incorrect understanding of the code. Per my tutorial, the "B" mode string (meaning "Box") is an automated selection method, and should therefore be supplied with two points corresponding to two opposite corners of a rectangle (the direction of the points also determining whether the selection is a crossing box or window box); this mode string will not prompt the user for a selection. However, the code to which you refer is very old! - I would likely rewrite it along the lines of: (defun c:delall ( / blk ent lay ) (while (progn (setvar 'errno 0) (setq ent (car (nentsel "\nSelect object on layer to delete <exit>: "))) (cond ( (= 7 (getvar 'errno)) (princ "\nMissed, try again.") ) ( (null ent) nil) ( (wcmatch (setq lay (cdr (assoc 8 (entget ent)))) "*|*") (princ "\nCannot delete xref-dependent objects.") ) ( (= 4 (logand 4 (cdr (assoc 70 (tblsearch "layer" lay))))) (princ "\nObjects reside on a locked layer.") ) ( t (vlax-for def (cond (blk) ((setq blk (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))))) (if (= :vlax-false (vla-get-isxref def)) (vlax-for obj def (if (and (= lay (vla-get-layer obj)) (vlax-write-enabled-p obj)) (vla-delete obj) ) ) ) ) t ) ) ) ) (princ) ) (vl-load-com) (princ) Edited October 5, 2018 by Lee Mac 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.