TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Lupo76 on August 30, 2016, 06:21:49 AM

Title: Select objects by true color
Post by: Lupo76 on August 30, 2016, 06:21:49 AM
Hello,
I have the need to realize a selection set of all objects with a given TrueColor.

I could use the following code to check the color of each object, but I hope there is a more powerful way to do this:
Code: [Select]
          (setq oColor (vlax-get-property (vlax-ename->vla-object ent1) 'TrueColor))
          (setq clrR (vlax-get-property oColor 'Red))
          (setq clrG (vlax-get-property oColor 'Green))
          (setq clrB (vlax-get-property oColor 'Blue))

Unfortunately the ssget filters (62) I can not look for TrueColor :-(

Have you any suggestions?
Title: Re: Select objects by true color
Post by: roy_043 on August 30, 2016, 06:37:26 AM
Create two entities. One with an aci color the other with a true color. Compare entity lists... Conclusion...
Title: Re: Select objects by true color
Post by: kpblc on August 30, 2016, 06:49:18 AM
As i rememer, TrueColors are stored at 420 DXF group
Title: Re: Select objects by true color
Post by: rkmcswain on August 30, 2016, 08:22:42 AM
As @kpblc said...


Code: [Select]
(ssget "_X" '((420 . 4187673)))


See also: http://adndevblog.typepad.com/autocad/2013/01/how-to-access-the-truecolor-property-via-autolisp.html



Title: Re: Select objects by true color
Post by: Grrr1337 on August 30, 2016, 03:00:34 PM
After reading the comments, I've put something together (since I've had the same need once) :
Code: [Select]
; Grrr
; Select objects by their truecolour (doesn't work for entity whos color is an "index color" or "Bylayer/Byblock")
(defun C:test ( / SysVarLst *error* e ex tc SS )
(setvar 'errno 0)(sssetfirst nil nil)

(defun *error* ( msg )
(mapcar '(lambda ( n v / ) (setvar n v)) (mapcar 'car SysVarLst) (mapcar 'cadr SysVarLst))
(if (not (member msg '("Function cancelled" "quit / exit abort")))
(princ (strcat "\nError: " msg))
)
(princ)
)

(setq SysVarLst
(mapcar '(lambda ( a b / ) (list a (getvar a) b))
(list "CLIPROMPTLINES" "CMDECHO" "PDMODE") ; PDMODE, because sometimes is hard to (entsel) a point with PDMODE of 0 value
(list 3 0 3) ; the new intended values
)
)

(mapcar '(lambda ( n v / ) (setvar n v)) (mapcar 'car SysVarLst) (mapcar 'caddr SysVarLst))
(while
(not
(and
(setq e (car (entsel "\nSelect source entity to filter by its TrueColour: ")))
(setq ex (entget e))
(member 420 (mapcar 'car ex))
(setq tc (cdr (assoc 420 ex)))
)
)
(cond
((and e (not tc)) (princ "\nThis entity doesn't have TrueColour!"))
((or (member (getvar 'errno) '(7 52)) (null e)) (princ "\nMissed, try again!"))
)
)

;; Convert TrueColor into a list of RGB
;; by Gopinath Taget from adndevblog.typepad.com:
(defun TrueColorToRGB (tcol)
(list
(lsh tcol -16) ; R
(lsh (lsh tcol 16) -24) ; G
(lsh (lsh tcol 24) -24) ; B
)
); defun

(princ (strcat "\nSelect objects to filter by \"" (vl-princ-to-string (TrueColorToRGB tc)) "\" TrueColour! "))

(if (setq SS (ssget "_:L" (list (cons 420 tc) (cons 410 (getvar 'ctab)))))
(progn
(princ (strcat "\nSelected " (itoa (sslength SS)) " objects!"))
(sssetfirst nil SS)
)
)
(mapcar '(lambda ( n v / ) (setvar n v)) (mapcar 'car SysVarLst) (mapcar 'cadr SysVarLst))

(princ)
);| defun |; (vl-load-com) (princ)

Title: Re: Select objects by true color
Post by: alanjt on August 30, 2016, 04:30:43 PM
Made me think to updated my FilteredSelection tool to account for TrueColor.

https://www.theswamp.org/index.php?topic=35028.0 (https://www.theswamp.org/index.php?topic=35028.0)
Title: Re: Select objects by true color
Post by: Lupo76 on August 31, 2016, 04:31:58 AM
Thank you all!
I simply solved with:

(ssget "_X" '((420 . 4187673)))