Author Topic: get TrueColor for every layer & make it dtext  (Read 1660 times)

0 Members and 1 Guest are viewing this topic.

pyreflos

  • Guest
get TrueColor for every layer & make it dtext
« on: November 29, 2017, 09:13:58 PM »
I'm putting together a script that draws a line, and writes out the layer name, description, color, & lineweight for every layer in a drawing. It works great. But I want it to also give me the rgb color value. It's easy enough grab the info, but I can't seem to print it...

I can get color (indexed) and truecolor (RGB):
(setq layc (vla-get-Color lay))
(setq laytc (vla-get-TrueColor lay))

And I can write out indexed color:

(command "text" "j" "ml" (list dx5 dyy) "0.09375" "0" layc)
"5"

But TrueColor is confounding me... the closest I get is:

(command "text" "j" "ml" (list dx6 dyy) "0.09375" "0" (vl-princ-to-string laytc)) ;;; works, bad form
"#<VLA-OBJECT IAcadAcCmColor 0000000072c40f90>"

I also tried this, which chokes on layer one and stops the script:
(command "text" "j" "ml" (list dx5 dyy) "0.09375" "0" laytc)  ;;; does not work
"Enter text: ; error: bad argument value: AutoCAD command: #<VLA-OBJECT IAcadAcCmColor 0000000072ab2ca0>"

Does anyone know what form true color is in and how to convert ir to a "r,g,b" string?

BIGAL

  • Swamp Rat
  • Posts: 1398
  • 40 + years of using Autocad
Re: get TrueColor for every layer & make it dtext
« Reply #1 on: November 29, 2017, 10:48:12 PM »
here is one way just "get" the red green blue
Command: (vlax-dump-object laytc)
; IAcadAcCmColor: AutoCAD AcCmColor Interface
; Property values:
;   Blue (RO) = 255
;   BookName (RO) = ""
;   ColorIndex = 4
;   ColorMethod = 195
;   ColorName (RO) = ""
;   EntityColor = -1023410172
;   Green (RO) = 255
;   Red (RO) = 0
T
A man who never made a mistake never made anything

ronjonp

  • Needs a day job
  • Posts: 7526
Re: get TrueColor for every layer & make it dtext
« Reply #2 on: November 30, 2017, 09:56:34 AM »
Code - Auto/Visual Lisp: [Select]
  1.   ","
  2.          (mapcar '(lambda (x) (strcat (itoa (vlax-get laytc x)) ",")) (list 'red 'green 'blue))
  3.   )
  4. )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

BIGAL

  • Swamp Rat
  • Posts: 1398
  • 40 + years of using Autocad
Re: get TrueColor for every layer & make it dtext
« Reply #3 on: November 30, 2017, 07:16:47 PM »
Nice one ronjop very usefull where you want more than one item a couple comes to mind 'startpoint 'endpoint
A man who never made a mistake never made anything

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: get TrueColor for every layer & make it dtext
« Reply #4 on: November 30, 2017, 07:24:46 PM »
FWIW you could avoid the multiple quotes:

Code: [Select]
(list 'red 'green 'blue)>>>
Code: [Select]
'(red green blue)
(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