teknomatika Posted September 20, 2011 Posted September 20, 2011 I need one more help: I need an autolisp routine that allows from a pick in just one entity, select all entities in drwaing that have the same color property. The entities can be multiple and belong to different layers. It is true that in autocad the "qselect" tool already exists, but this does not always work, in addition to not being very direct. Tanks. Quote
Tharwat Posted September 20, 2011 Posted September 20, 2011 This ?..... (sssetfirst nil (ssget "_X" (list (cons 62 1)))) ;;; Number one indicates to color Red Quote
Lee Mac Posted September 20, 2011 Posted September 20, 2011 This? (defun c:SelectByColour ( / c d e l ) (if (setq e (car (entsel))) (progn (setq c (cond ( (cdr (assoc 62 (entget e))) ) ( (abs (cdr (assoc 62 (tblsearch "LAYER" (cdr (assoc 8 (entget e))))))) ) ) ) (while (setq d (tblnext "LAYER" (null d))) (if (= c (abs (cdr (assoc 62 d)))) (setq l (cons "," (cons (cdr (assoc 2 d)) l))) ) ) (sssetfirst nil (ssget "_X" (if l (list (cons -4 "<OR") (cons 62 c) (cons -4 "<AND") (cons 62 256) (cons 8 (apply 'strcat (cdr l))) (cons -4 "AND>") (cons -4 "OR>") ) (list (cons 62 c)) ) ) ) ) ) (princ) ) Quote
teknomatika Posted September 20, 2011 Author Posted September 20, 2011 Lee Mac, Excellent. That's right. Much more direct than the QSELECT. However, I found that in the case of blocks, the selection includes the native color of the layer, even when the color of block it is different. But this is a detail. Tanks. Quote
Lee Mac Posted September 20, 2011 Posted September 20, 2011 However, I found that in the case of blocks, the selection includes the native color of the layer, even when the color of block it is different. You will only be able to select Primary entities with ssget. 1 Quote
teknomatika Posted September 20, 2011 Author Posted September 20, 2011 I understand. Anyway, the routine is excellent. Thank you. Quote
alanjt Posted September 21, 2011 Posted September 21, 2011 This may be of interest to you (the FilteredSelection.LSP file): http://www.theswamp.org/index.php?topic=35028.msg402471#msg402471 eg. Command: ft Filter choice: [block/Color/Entity/Layer/linetYpe] <Layer>: c Ignore locked layers? [Yes/No] <No>: Select object for color: Color: "(5 . Blue)" selected. Select objects: Specify opposite corner: 1 found Select objects: al 1 found (1 duplicate), 1 total Select objects: You can also use SSX or Filter Quote
bkartal16 Posted August 17, 2020 Posted August 17, 2020 Hello, is it possible to select by given index color (1:red, 2:yellow, 3:green etc) instead of select source object? Quote
BIGAL Posted August 18, 2020 Posted August 18, 2020 Maybe use repeat for each color number, see Tharwat post. Enter a string say 1,2,3 use parse csv to make a list then a foreach to process the list. Similar to 1st suggestion how do you want to do the 1 2 3 ? Quote
bkartal16 Posted August 18, 2020 Posted August 18, 2020 (defun c:SelectByColour ( / c d e l ) (if (setq e (getint "\nColour index :")) (progn (setq c (cond ( e ) ( (abs (cdr (assoc 62 (tblsearch "LAYER" 0)))) ) ) ) (while (setq d (tblnext "LAYER" (null d))) (if (= c (abs (cdr (assoc 62 d)))) (setq l (cons "," (cons (cdr (assoc 2 d)) l))) ) ) (sssetfirst nil (ssget (if l (list (cons -4 "<OR") (cons 62 c) (cons -4 "<AND") (cons 62 256) (cons 8 (apply 'strcat (cdr l))) (cons -4 "AND>") (cons -4 "OR>") ) (list (cons 62 c)) ) ) ) ) ) (princ) ) I have adopt above LeeMac code acc. to my need. thnx. I dont know if it is logical but it works :) Quote
Tharwat Posted August 18, 2020 Posted August 18, 2020 Untested. (defun c:SelectByColour (/ c d l) (if (setq c (getint "\nColour index :")) (progn (while (setq d (tblnext "LAYER" (null d))) (if (= c (abs (cdr (assoc 62 d)))) (setq l (cons "," (cons (cdr (assoc 2 d)) l))) ) ) (sssetfirst nil (ssget (if l (list (cons -4 "<OR") (cons 62 c) (cons -4 "<AND") (cons 62 256) (cons 8 (apply 'strcat (cdr l))) (cons -4 "AND>") (cons -4 "OR>") ) (list (cons 62 c)) ) ) ) ) ) (princ) ) Quote
hseeda Posted July 30, 2022 Posted July 30, 2022 (edited) This is shorter (sorry Lee Mac: any comment is appreciated) (defun c:SelectByColor(/ TargEnt TargColor) (setq TargEnt (car (entsel "\nSelect object with Color to select: "))) (setq TargColor (assoc 62 (entget TargEnt))) (sssetfirst nil (ssget "_X" (list TargColor))) (print TargColor) (princ) ) Note: doesnt work for "ByLayer" Color. Lee Mack's is perfet as alwayse Edited July 30, 2022 by hseeda Quote
Lee Mac Posted July 31, 2022 Posted July 31, 2022 On 7/30/2022 at 2:21 PM, hseeda said: This is shorter (sorry Lee Mac: any comment is appreciated) (defun c:SelectByColor(/ TargEnt TargColor) (setq TargEnt (car (entsel "\nSelect object with Color to select: "))) (setq TargColor (assoc 62 (entget TargEnt))) (sssetfirst nil (ssget "_X" (list TargColor))) (print TargColor) (princ) ) Note: doesnt work for "ByLayer" Color. Lee Mack's is perfet as alwayse Be sure to also test for a valid selection prior to calling (entget TargEnt) otherwise your code will error. 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.