@Kyudos wrote:
I'm looking for some LISP to invert the AutoCAD selection - deselect all selected items, and select all those not selected (forming a new selection set). Ideally, it would only work on the current selection (the PICKFIRST selection).
....
Here's my take on it -- very lightly tested, but it works in noun-verb or verb-noun mode [i.e. if you have anything pre-selected when you enter the command, it selects/grips/highlights everything except that pre-selection, or if you don't, it asks you to select objects, then selects/grips/highlights everything except those].
(defun C:SAB (/ ss); = Select All But
(setq ss
(cond
((ssget "_I")); preselection, if any
((ssget)); User selection if no pre-selection
); cond
); setq
(sssetfirst nil); clear preselection, if any, to not to in at Select command
(command "_.select" "_all" "_remove" ss "")
(sssetfirst nil (ssget "_P")); select/grip/highlight
); defun
Add an appropriate prompt if desired, and/or put the final selection into a variable if needed, etc. If you really want it to work only with a pre-selection, isolate that out of the (cond) function and dump the User-selection part.
It has a slightly different effect than the versions using (ssget "_X"), since those will find everything in the drawing, even in other than the current space, whereas this will work only with things in the current space. Depending on what you plan to do with the result, that may be preferable, anyway.
EDIT: In fact, if you want it to work only with pre-selection, there isn't even any need for the 'ss' variable:
(defun C:SAB ()
(if (ssget "_I")
(progn ; then
(sssetfirst nil)
(command "_.select" "_all" "_remove" (ssget "_P") "")
(sssetfirst nil (ssget "_P"))
)
(prompt "\nRequires pre-selection."); else
); if
); defun
Kent Cooper, AIA