ollie Posted May 22, 2009 Posted May 22, 2009 Hi Folks, I have tried on numerous occasions to use a variable instead of a string for filter lists with no success (setq sset (ssget "X" ' ((2 . "BLOCKNAME")))) ;This works fine (setq BLOCKNAME "Testblock") (setq sset (ssget "X" ' (2 . BLOCKNAME)))) ;this returns an error along the lines of: Bad filter in ssget Is there something i am missing? Thanks, Ollie Quote
jammie Posted May 22, 2009 Posted May 22, 2009 Ollie, If you would like to pass a variable to a selection set you need to use LIST instead of QUOTE This should work (setq BLOCKNAME "Testblock") (setq sset (ssget "X" ([color="blue"]list[/color] (cons 2 BLOCKNAME)))) The main difference between LIST and QUOTE is that QUOTE returns an expression without evaluating. Using LIST allows all expressions to be evaluated before the actual list is created (setq sset (ssget "X" '((2 . "BLOCKNAME")))) It was fine in your first example where you state what blockname to search for. Nothing needs to be evaluated, AutoCAD simply assumes the selection filter is correct and searches for the relevant objects (setq BLOCKNAME "Testblock")(setq sset (ssget "X" ' (2 . BLOCKNAME)))) In the second example you are trying to pass a variable into the selection set. To make sense of this AutoCAD would first need to evaluate the filter and then search for the objects.In this instance LIST is appropriate Hope this makes a bit of sense Regards, Jammie Quote
ollie Posted May 22, 2009 Author Posted May 22, 2009 Jammie: Thanks that works great. Also thanks for the breakdown of why it works. I've learned alot from it Ollie Quote
Freerefill Posted May 22, 2009 Posted May 22, 2009 Here's a fun thing. Try typing: (type 'something) at the command line, and see what it returns. Compare it to: (type "something") Also, try looking up the (vl-symbol-name) and (read) functions in the AutoLISP help files. Quote
jammie Posted May 22, 2009 Posted May 22, 2009 Jammie: Thanks that works great. Also thanks for the breakdown of why it works. I've learned alot from it Ollie No problem, your welcome! Glad to help Jammie 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.