Select entities having same color in the same layer

Select entities having same color in the same layer

k_ngo-quoc
Enthusiast Enthusiast
1,245 Views
9 Replies
Message 1 of 10

Select entities having same color in the same layer

k_ngo-quoc
Enthusiast
Enthusiast

Hi,

I have entities with differents colors in the same layer. How could i select all the entities with the same color by clicking the color select? And the second question is how can i select only the polylines having the same color.

Thanks for your help.

 -

0 Likes
Accepted solutions (2)
1,246 Views
9 Replies
Replies (9)
Message 2 of 10

mduvalAA6EJ
Enthusiast
Enthusiast
"Filter" command
0 Likes
Message 3 of 10

Kent1Cooper
Consultant
Consultant

FILTER is good, as suggested.  To automate such a thing, if you are not using AutoCAD LT, look into the AutoLisp (ssget) function [>here<] and use selection set filters.  What it finds can be stored in a variable, and/or selected/gripped/highlighted, depending on what you need to do with the results.  For example:

 

To find all objects on a given Layer that are green [by color override, not ByLayer on a green Layer]:

(ssget "_X" '((8 . "YourLayerName") (62 . 3)))

 

To find all Polylines that are green regardless of Layer:

 

(ssget "_X" '((0 . "*POLYLINE") (62 . 3)))

 

Kent Cooper, AIA
Message 4 of 10

k_ngo-quoc
Enthusiast
Enthusiast

Thanks for your informations. However, i'm not very good in lisp. How can you translate into a program.

Thank for your help!

0 Likes
Message 5 of 10

Kent1Cooper
Consultant
Consultant

@k_ngo-quoc wrote:

..... How can you translate into a program. ....


Selecting them is one thing, but beyond that the possibilities, and the other AutoLisp functions that could be involved, are endless.  In other words -- a program to do what?

 

For a simple example, if you want to simply find and select/highlight/grip all objects of a color that you select from the color dialog box [your first question in Message 1 -- and again, those with that color as an override, not the color of their Layer], so that you can then use them as a pre-selection to call an editing command, or change something about them in the Properties palette:

 

(defun C:SABC (/ clr); = SelectAllByColor
  (setq clr (acad_colordlg 256))
  (sssetfirst nil (ssget "_X" (list (cons 62 clr))))
)

 

Kent Cooper, AIA
Message 6 of 10

k_ngo-quoc
Enthusiast
Enthusiast

Your program is selected for all the entities belong the same color in differents layers.

what i need that i can select only the entities belong to the same color in the same layer (only one layer) by clicking the object (and not by the  properties palette).

Thanks advance.

0 Likes
Message 7 of 10

k_ngo-quoc
Enthusiast
Enthusiast

An example in dwg.

0 Likes
Message 8 of 10

Kent1Cooper
Consultant
Consultant
Accepted solution

@k_ngo-quoc wrote:

....what i need that i can select only the entities belong to the same color in the same layer (only one layer) by clicking the object (and not by the  properties palette).

.....


SELECTSIMILAR

Kent Cooper, AIA
Message 9 of 10

Kent1Cooper
Consultant
Consultant
Accepted solution

@k_ngo-quoc wrote:

An example in dwg.


[But SELECTSIMILAR seems to find only the same object type, regardless of other settings.]

 

First solution:

 

(defun C:SimLayerColor (/ ent edata)
  (setq ent (car (entsel)) edata (entget ent))
  (sssetfirst nil (ssget "_X" (list (assoc 8 edata) (assoc 62 edata))))
)

 

Second solution:

 

(defun C:SimObjLayerColor (/ ent edata)
  (setq ent (car (entsel)) edata (entget ent))
  (sssetfirst nil (ssget "_X" (list (assoc 0 edata) (assoc 8 edata) (assoc 62 edata))))
)

 

Kent Cooper, AIA
0 Likes
Message 10 of 10

k_ngo-quoc
Enthusiast
Enthusiast

That's perfect!

Thanks again!

0 Likes