Jump to content

SSGET Filters


AdamW

Recommended Posts

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.

Link to comment
Share on other sites

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 by Tharwat
  • Like 1
Link to comment
Share on other sites

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 by Lee Mac
Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...