Author Topic: Select objects by true color  (Read 2162 times)

0 Members and 1 Guest are viewing this topic.

Lupo76

  • Bull Frog
  • Posts: 343
Select objects by true color
« 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?

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Select objects by true color
« Reply #1 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...

kpblc

  • Bull Frog
  • Posts: 396
Re: Select objects by true color
« Reply #2 on: August 30, 2016, 06:49:18 AM »
As i rememer, TrueColors are stored at 420 DXF group
Sorry for my English.

rkmcswain

  • Swamp Rat
  • Posts: 978
Re: Select objects by true color
« Reply #3 on: August 30, 2016, 08:22:42 AM »

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Select objects by true color
« Reply #4 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)

(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Select objects by true color
« Reply #5 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
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Lupo76

  • Bull Frog
  • Posts: 343
Re: Select objects by true color
« Reply #6 on: August 31, 2016, 04:31:58 AM »
Thank you all!
I simply solved with:

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