I have created a lisp that selects entities or objects on a certain layer.
It worked great until I added the option 'Pick-Layer'. I cannot for the life of me input to a variable the coorect format list for the filter. It should return something like:
((8. "LAYER1"))
With double parentheses at each end.
But the best I can get it to do is:
(8 . "LAYER1")
(single parentheses )
I've tried several ways, but the code fails when it tries to read the variable (lay) with the picked layer .
(defun c:Select_Items ( / ent filt lay optn sset) (initget "Text Attributes Blocks Lines PLines Pick-Layer Layer-Dimensions Layer-No-Print Layer-Screen Layer-Text") (setq optn (cond ((getkword "\n [Text/Attributes/Blocks/Lines/PLines/Layer-Dimensions/Pick-Layer/Layer-No-Print/Layer-Screen/Layer-Text] <Text>")) ("Text"))) (cond ((equal optn "Attributes") (setq filt '((0 . "ATTDEF"))) ) ((equal optn "Blocks") (setq filt '((0 . "INSERT"))) ) ((equal optn "Lines") (setq filt '((0 . "LINE"))) ) ((equal optn "PLines") (setq filt '((0 . "LWPOLYLINE"))) ) ((equal optn "Text") (setq filt '((0 . "*TEXT"))) ) ((equal optn "Pick-Layer") (setq ent (car (entsel "\nSelect object to choose layer: "))) (setq lay (cdr(assoc 8 (entget ent)))) (setq filt '((8 . lay))) ;(setq optn (strcat "Layer " lay)) ) ((equal optn "Layer-Dimensions") (setq filt '((8 . "DIMENSIONS"))) ) ((equal optn "Layer-Screen") (setq filt '((8 . "SCREEN"))) ) ((equal optn "Layer-No-Print") (setq filt '((8 . "NO PRINT"))) ) ((equal optn "Layer-Text") (setq filt '((8 . "TEXT"))) ) );; end cond (sssetfirst nil (setq sset (ssget filt))) (if sset (princ (strcat "\n "(itoa (sslength sset)) " "optn" Items Selected")) (princ (strcat "\n No " optn " Selected")) ) (princ) )
The code works fine using all the other options except that one
Solved! Go to Solution.
Solved by Kent1Cooper. Go to Solution.
Change this:
(setq filt '((8 . lay)))
to this:
(setq filt (list (cons 8 lay)))
A "quoted" list [the apostrophe prefix] means there is nothing inside it that needs to be evaluated, but you do need to evaluate what's in the 'lay' variable in that situation.
EDIT: A simplification for you --
Rather than extract the Layer name from the 8-code entry in the entity data list, and then put it back into another 8-code entry for the filter, you can leave it associated with its 8, replacing this part:
(setq lay (cdr(assoc 8 (entget ent)))) (setq filt '((8 . lay)))
with just this, omitting the 'lay' variable entirely:
(setq filt (list (assoc 8 (entget ent))))
Gnarrrrrrrgh!
I spent several hours tustling with that , trying all sorts of things!!
Thank you very much Kent, so easy when shown how
Further to the earlier reply, the following is a valuable bit of knowlege to remember:
'A "quoted" list [the apostrophe prefix] means there is nothing inside it that needs to be evaluated, but you do need to evaluate what's in the 'lay' variable in that situation.'
I didn't know that, I thought they were interchangeable, also I missed the fact that I already had a dotted pait from the assoc, I was rewriting it manually!
Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.