Jump to content

Recommended Posts

Posted

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

Posted

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

Posted

Jammie: Thanks that works great. Also thanks for the breakdown of why it works. I've learned alot from it

 

 

 

Ollie

Posted

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.

Posted
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

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...