I'm trying to get all plines/lines/arcs that are the color of a selected entity wether that is entity is bylayer or not. The following is an excerpt from a routine that adds several entities types selected by color or other forms of user input. I'm stuck on how to get desired selection sets. ((= ME "C") (setq PT1 (getpoint "\nSelect Entity for Color: ")) (SETQ SS1 (ssget PT1)) (SETQ ENT (entget (ssname ss1 0))) (IF (= (CDR (assoc 62 ENT)) NIL) (PROGN (SETQ ENTCOLOR (CDR (ASSOC 62 (TBLSEARCH "LAYER" (CDR (ASSOC 8 ENT)))))) (SETQ ENTL (LAYLIST ENTCOLOR)) (setq ENTPAIR (mapcar '(lambda (x) (cons 8 x)) entl)) ;<-------PAIR WITH NO DOTS stuck here...not sure how to get my selection sets. I'm trying to get all plines/lines/arcs that are the color of a selected entity wether that is entity is bylayer or not. The following function was harvested from this group on another topic. However, I get a list of layer names only and not sure how to get them into a selection set that gets the elements I want. Also I need some structure assistance so if the entity color is not bylayer I get the same results. Please help me over this logic hurdle. ;TO GET layers with a certain color IN A LIST: ;-------------------------------------------------------------------------------- (defun laylist (color / ) (setq *acad* (vlax-get-acad-object)) (setq *doc* (vla-get-activedocument *acad*)) (setq layers (vla-get-layers *doc*)) (vlax-for x layers (if (= (vla-get-color x) color) (setq layerlist (cons (list 8 (vla-get-name x)) layerlist)) ) ) ) This is my first query into this group and would be grateful for input. Could not find exact condition in search of previous posts. Mary
((= ME "C") (setq PT1 (getpoint "\nSelect Entity for Color: ")) (SETQ SS1 (ssget PT1)) (SETQ ENT (entget (ssname ss1 0))) (IF (/= (CDR (assoc 62 ENT)) NIL) (PROGN (SETQ ENTCOLOR (CDR (ASSOC 62 (TBLSEARCH "LAYER" (CDR (ASSOC 8 ENT)))))) (SETQ ENTL (LAYLIST ENTCOLOR)) ;(setq ENTPAIR (mapcar '(lambda (x) (cons 8 x)) entl)) ;<-------PAIR WITH NO DOTS (setq ss (ssget "X" (list (cons 8 ENTL)(cons 62 ENTCOLOR)))); All with matching color and Layer (setq ss (ssget "X" (list (cons 62 ENTCOLOR))); All with matching color Bob
Thanks Bob but I get a bad SSGET list value with the first suggested line. My ENTL returns a list of layer names such as (("Plastic") ("Stainless_Trim") ("Galv-Steel") ("By_Others") ("Gaskets") ("Title_Block") ("0")) (Con 8 entl) doesn't work in any combo I tried. I'm trying the other suggestion next. Thanks for the response. repost for this one...first had an experiemental attempt to 'cons the 8 there. (defun laylist (color / ) (setq *acad* (vlax-get-acad-object)) (setq *doc* (vla-get-activedocument *acad*)) (setq layers (vla-get-layers *doc*)) (vlax-for x layers (if (= (vla-get-color x) color) (setq layerlist (cons (list (vla-get-name x)) layerlist)) ) ) )
(setq ss (ssget "x" (list (cons 8 (cdr (assoc 2 n)))(cons 62 1))) ;will get entities with red color. (setq ss (ssget "x" (list (cons -4 "<AND")(cons 8 "LAYERNAME)(cons -4 "<OR")(cons 62 1)(cons 62 256)(cons -4 "OR>")(cons -4 "AND>")))) Will select all entities on a layer that is either red or bylayer. So you will need to check the layer names for the right color. Get list of layers: (setq lt1 (list (tblnext "LAYER" T)) ) (while (setq l (tblnext "LAYER")) (setq lt1 (cons l lt1) ) ) So check each layer for right color: (foreach n lt1 (if (= (cdr (assoc 62 n)) 1) ;;Use ssget code here if true. ;;Then process ss or add to another saved sset. ) ) Bill
Oh, I forgot to have you change the line: (SETQ ENTL (LAYLIST ENTCOLOR)) to: (setq ENTL (cdr (assoc 8 ENT))); get layer name of entity Sorry bout that. Bill's filter looks more interesting anyway. Bob
Here's my version. This will find all objects on layers with the specified color that are not defined with a different color, and all objects defined with the specified color that are on other layers Example (selbycolor 1) will get all red objects (defun laylist (color / ) (setq *acad* (vlax-get-acad-object)) (setq *doc* (vla-get-activedocument *acad*)) (setq layers (vla-get-layers *doc*)) (setq layerlist "") (vlax-for x layers (if (= (vla-get-color x) color) (setq layerlist (strcat layerlist (vla-get-name x) ",")) ) ) (setq layerlist (vl-string-trim "," layerlist)) ) (defun selbycolor (color / cnt ss ename) (laylist color) ;get alll objects of the specified color or on a layer of the specified color (setq ss (ssget "x" (list (cons -4 "<OR") (cons 8 layerlist) (cons 62 color) (cons -4 "OR>") ) )) (setq ss (if ss ss (ssadd))) (setq cnt (sslength ss)) ;filter out all objects selected layers that are of a different color (while (> cnt 0) (setq cnt (1- cnt)) (setq ename (ssname ss cnt)) (if (assoc 62 (entget ename)) (if (/= (cdr (assoc 62 (entget ename))) color) (ssdel ename ss) ) ) (setq cnt (1- cnt)) ) (princ (strcat "\n" (itoa (sslength ss)) " objects found for color " (itoa color))) (princ) ) entity wether that is entity is bylayer or not. The following is an excerpt from a routine that adds several entities types selected by color or other forms of user input. plines/lines/arcs that are the color of a selected entity wether that is entity is bylayer or not. However, I get a list of layer names only and not sure how to get them into a selection set that gets the elements I want. Also I need some structure assistance so if the entity color is not bylayer I get the same results. Please help me over this logic hurdle. Could not find exact condition in search of previous posts.
Thanks a lot. This is the logic I needed. However, please help me over the following simple stumper. Learning heaps with these problems. I have a sample file with some entities red as a test but I get a bad ssget with the first suggestion as noted per your post; (setq ss (ssget "x" (list (cons 8 (cdr (assoc 2 n)))(cons 62 1))) ;will get entities with red color. (assoc 2 n); <-----can you please clarify? Tks. M.
Study Bill's example ... the n is the nth item in lt1.. as per: (foreach n lt1 (if (= (cdr (assoc 62 n)) 1) ;;Use ssget code here if true. ;;Then process ss or add to another saved sset. ) ) Above would 'cycle' through the selection set lt1, setting each n (loop entity). In your example, just use 'ent' for the entity. Bob
You rock Jim. That's it! Thanks for your gracious sharing of these. I see that you were the author of the posted function I harvested earlier. I feel priviledged for your reponse. For my use it'll just need to be modified to just get polylines/lines and arc from that last selection set. Mary
You're welcome. This should take care of selecting polylines, lines and arcs (defun selbycolor (color / cnt ss ename) (laylist color) ;get alll objects of the specified color or on a layer of the specified color (setq ss (ssget "x" (list (cons -4 "<AND") (cons 0 "LWPOLYLINE,POLYLINE,LINE,ARC") (cons -4 "<OR") (cons 8 layerlist) (cons 62 color) (cons -4 "OR>") (cons -4 "AND>") ) )) (setq ss (if ss ss (ssadd))) (setq cnt (sslength ss)) ;filter out all objects selected layers that are of a different color (while (> cnt 0) (setq cnt (1- cnt)) (setq ename (ssname ss cnt)) (if (assoc 62 (entget ename)) (if (/= (cdr (assoc 62 (entget ename))) color) (ssdel ename ss) ) ) (setq cnt (1- cnt)) ) (princ (strcat "\n" (itoa (sslength ss)) " objects found for color " (itoa color))) (princ) ) of the posted function I harvested earlier. I feel priviledged for your reponse. and arc from that last selection set.