Jump to content

Query language in AutoCAD?


Recommended Posts

Posted

Hi,

 

Does there exist any “object filter” ability in AutoCAD? Each AutoCAD file might contain as many as hundreds of individual elements, and each has different property. There might frequently arise needs to:

  1. Select all objects on a single layer
  2. Select all objects whose color are blue
  3. Select all annotative objects.

 

How to address these needs? If by eye inspection and manual selection, it is very inefficient and error-prone. Is there a way to done this automatically using some sort of query language?

 

 

Bob

Posted

not sure about option 3 but QSELECT will pick up the others.

You could also try FILTER but I have never used that so can't personally comment.

 

Failing that a selection set in any of the programming languages will also allow you to create sets on those parameters. I prefer VBA but LISP is probably more efficient for selection sets.

Posted

QSELECT did the job, thanks.

 

I also tried FILTER and it appeared to be more complicated so I didn't pursue it further.

 

 

Bob

Posted
QSELECT did the job, thanks.

 

I also tried FILTER and it appeared to be more complicated so I didn't pursue it further.

 

 

Bob

Just a tip, even though it looks more difficult, FILTER has many more advantages than QSELECT. For one, you can actually save selection sets for future use. That's a big one for me.
Posted

What Tannar said.....

Remember, with complexity comes versatility.... :D

 

2. Select all objects whose color are blue

 

Remember that by default, neither QSELECT or FILTER will select objects that appear blue because they reside on a "blue" layer, and their actual color is "bylayer".

Posted
Just a tip, even though it looks more difficult, FILTER has many more advantages than QSELECT. For one, you can actually save selection sets for future use. That's a big one for me.

 

This could be useful. Thanks for reminding.

Posted
What Tannar said.....

Remember, with complexity comes versatility.... :D

 

 

 

Remember that by default, neither QSELECT or FILTER will select objects that appear blue because they reside on a "blue" layer, and their actual color is "bylayer".

 

I see it, many thanks.

 

Bob

Posted (edited)

Yep the only way to select all "Blue" entities (even those which are ByLayer on a Blue layer) would be with some coding (probably Lisp). The Filter is even more nice in that it remembers the previous filter by default, i.e. type 'Filter and click OK, instead of going though all the steps again using QSelect.

 

BTW, for me the simplest way of using Filter is to use the "Add Selected Object" button at the bottom left and pick one of the entities I want to select. Then Delete the lines in the top list which aren't needed.

 

For a lisp which selects all entities displayed as Blue:

(defun FilterForColor (col / lay llst)
 (setq llst "")
 (while (setq lay (tblnext "LAYER" (not lay)))
   (if (= (cdr (assoc 62 lay)) col)
     (setq llst (strcat llst "," (cdr (assoc 2 lay))))
   )
 )
 (setq llst (substr llst 2))
 (append (list '(-4 . "<OR") (cons 62 col))
         (if (eq llst "")
           '((62 . 256))
           (list '(-4 . "<AND") '(62 . 256) (cons 8 llst) '(-4 . "AND>"))
         )
         '((-4 . "OR>"))
 )
)

(defun c:SelectBlue (/)
 (sssetfirst nil (ssget "_X" (FilterForColor col)))
 (princ)
)

You can do similar for Layers, and to select all annotative stuff:

(defun c:SelectAnno (/)
 (sssetfirst nil (ssget "_X" '((-3 ("AcadAnnotative")))))
 (princ)
)

And to combine the 2:

 (defun c:SelectBlueAnno (/)
 (sssetfirst nil (ssget "_X" (append (FilterForColor 5) '((-3 ("AcadAnnotative"))))))
 (princ)
)

Edited by irneb
Simplified code
Posted

irneb,

 

It is a little bit overwhelming for me but I will definitely note it down to study later.

 

Bob

Posted

I never knew about the filter command and thats a neat tool

 

Here is a start Using filter command that selects all objects

--- On a layer with color blue and the object is set to Bylayer (in this example Layer1 and layer2 color is blue)

or

--- The object color's property is set to blue.

 

It filters by if the objects color property is blue or

if it is on any layer that is blue and it set to bylayer

 

Capture.PNG

Posted

That's exactly what my lisp does. It's just that the lisp figures out for itself which layers are set to blue. Using filter you need to remember the layer names.

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