Author Topic: Convert RGB Colors to Index Colors  (Read 16098 times)

0 Members and 1 Guest are viewing this topic.

gschmidt

  • Guest
Convert RGB Colors to Index Colors
« on: January 11, 2011, 09:40:41 AM »
Hi,

I have DXF files from external Software.
All Entities of this DXF are in Model Space.
All Entities are in RGB Colors. Also Black (index 7) colors are RGB 0,0,0
Most users have a Black (Model Space) background.
So you don't see the RGB 0,0,0 entities.

What I need:
In this DXF I want to Select all entities by "RGB color"
and convert them to the corresponding Index Color: (I onlywant to convert first 7 index colors)

e.g.
RGB Color 255,0,0 --> Index Color 1
RGB Color 255,255,0 --> Index Color 2
RGB Color 0,255,0 --> Index Color 3
RGB Color 0,255,255 --> Index Color 4
RGB Color 255,0,255 --> Index Color 5
RGB Color 0,0,255 --> Index Color 6
RGB Color 0,0,0 --> Index Color 7

I know that in AutoCAD I can select entities by RGB Color with (ssget "x" '((420 . Int number)))
But I work for this project with BricsCAD, and there is no DXF 420 option.

For now I use the (ssget "x" '((62 . Index Number))).
This works to get Index Colors 1-6
RGB 0,0,0 -->Black (7) however is difficult. I Have to use Index Color 18 to select all RGB 0,0,0 entities.
But officially color 18 corresponds with RGB 76,0,0
So there is the possibility that both RGB 76,0,0 & RGB 0,0,0 are converted to index 7, where only RGB 0,0,0 is needed.

Is there another way to select entities by truecolor?

Greetzzz,

Gerben










 

VVA

  • Newt
  • Posts: 166
Re: Convert RGB Colors to Index Colors
« Reply #1 on: January 11, 2011, 10:22:23 AM »
Try it
Code: [Select]
(defun C:RGB2ACI ( )
  (Color-to-ACIcolor)
  (command "_.Regenall")
  (princ)
  )
(defun Color-to-ACIcolor (/ txt count *error*)
  (defun *error* (msg)
    (princ msg)
    (mip:layer-status-restore)
    (princ)
  ) ;_ end of defun
  (mip:layer-status-save)
  (vlax-for Blk (vla-get-blocks
  (vla-get-activedocument (vlax-get-acad-object))
) ;_ end of vla-get-blocks
    (setq count 0)
    (grtext -1
    (setq txt
   (strcat "Inspecting objects: "
   (vla-get-name Blk)
   )
    )
    ) ;_ end of grtext
    (if (= (vla-get-isxref Blk) :vlax-false)
      (progn
(vlax-for Obj Blk
  (setq count (1+ count))
  (if (zerop (rem count 10))
    (grtext -1 (strcat txt " : " (itoa count)))
  )
  (if (and (vlax-write-enabled-p Obj)
   (vlax-property-available-p Obj 'Color)
      )
    (vla-put-color Obj (vla-get-color Obj))
  )
) ;_ end of vlax-for
      ) ;_ end of progn
    ) ;_ end of if
  ) ;_ end of vlax-for
  (vlax-for Lay (vla-get-layers
  (vla-get-activedocument (vlax-get-acad-object))
)
    (vla-put-color Lay (vla-get-color Lay))
  )
  (mip:layer-status-restore)
 )
(defun mip:layer-status-restore ()
    (foreach item *PD_LAYER_LST*
      (if (not (vlax-erased-p (car item)))
        (vl-catch-all-apply
          '(lambda ()
             (vla-put-lock (car item) (cdr (assoc "lock" (cdr item))))
             (vla-put-freeze (car item) (cdr (assoc "freeze" (cdr item))))
             ) ;_ end of lambda
          ) ;_ end of vl-catch-all-apply
        ) ;_ end of if
      ) ;_ end of foreach
    (setq *PD_LAYER_LST* nil)
    ) ;_ end of defun

  (defun mip:layer-status-save ()
    (setq *PD_LAYER_LST* nil)
    (vlax-for item (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
      (setq *PD_LAYER_LST* (cons (list item
                                  (cons "freeze" (vla-get-freeze item))
                                  (cons "lock" (vla-get-lock item))
                                  ) ;_ end of cons
                            *PD_LAYER_LST*
                            ) ;_ end of cons
            ) ;_ end of setq
      (vla-put-lock item :vlax-false)
      (if (= (vla-get-freeze item) :vlax-true)
      (vl-catch-all-apply '(lambda () (vla-put-freeze item :vlax-false))))
      ) ;_ end of vlax-for
    ) ;_ end of defun
(princ "\nType RGB2ACI in command line")(princ)

SOFITO_SOFT

  • Guest
Re: Convert RGB Colors to Index Colors
« Reply #2 on: January 18, 2011, 02:25:27 PM »
  :-)
DOSLib Programmer's Reference
Copyright © 1992-2010, Robert McNeel & Associates. All rights reserved.

Robert McNeel & Associates

3670 Woodland Park Avenue North

Seattle, WA 98103

Phone: (206) 545-7000

FAX: (206) 545-7321

Internet: http://www.mcneel.com

Support: dale@mcneel.com


dos_rgbtoaci
Converts a Red-Green-Blue (RGB) color value to the closest AutoCAD Color Index (ACI) value.


--------------------------------------------------------------------------------

Syntax
(dos_rgbtoaci red green blue)

(dos_rgbtoaci rgb)

dos_acitorgb
dos_rgbtogray
and otherrr... :)

andddd FREE !

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Convert RGB Colors to Index Colors
« Reply #3 on: January 18, 2011, 04:29:52 PM »

nivuahc

  • Guest
Re: Convert RGB Colors to Index Colors
« Reply #4 on: January 19, 2011, 08:26:08 AM »
Welcome to TheSwamp, gschmidt  :-)

SOFITO_SOFT

  • Guest
Re: Convert RGB Colors to Index Colors
« Reply #5 on: January 20, 2011, 12:24:50 PM »
Hello Lee:

http://lee-mac.com/colourconversion.html

(vl-catch-all-apply 'vla-SetColorBookColor <<<<< !!!!

but ... there really is someone who uses color books?
I've tried ... the files are protected, are edited by hand?
The color code is encrypted? is a tool to manage color books?
I find one of the least helpful things the AutoCAD interface.
thanks for sharing a vast wisdom.
Greetings from Madrid.

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Convert RGB Colors to Index Colors
« Reply #6 on: January 20, 2011, 03:56:06 PM »
Are you not trying to convert RGB to ACI (Index)?

EDIT: Apologies, I mistook you for the OP :oops:

Colour Books can be used to give colour to entities, what are you trying to do?
« Last Edit: January 20, 2011, 07:21:35 PM by Lee Mac »

LE3

  • Guest
Re: Convert RGB Colors to Index Colors
« Reply #7 on: January 20, 2011, 07:16:24 PM »
Greetings from Madrid.
I miss Madrid, some day will go back there.

Saludos! :)

SOFITO_SOFT

  • Guest
Re: Convert RGB Colors to Index Colors
« Reply #8 on: January 21, 2011, 08:36:15 AM »
Helo, swamp people:
I made some time ago an import from bmp to dwg. I studied a little issue, I resolved with DOSLib. But I was curious about the color-books. I discovered the color-book editor of Autodesk and played a little with the matter. They call me attention is the method little developed.
Greetings. I post one example of conversion rgb -> ACi with a comic ilustration.

SOFITO_SOFT

  • Guest
Re: Convert RGB Colors to Index Colors
« Reply #9 on: January 21, 2011, 08:39:58 AM »
Greetings from Madrid.
I miss Madrid, some day will go back there.

Saludos! :)

You must wait for spring .... Now it is terribly cold. Greetings :))
Debes esperar a la primavera....Ahora hace un frio terrible. Saludos :))

SOFITO_SOFT

  • Guest
Re: Convert RGB Colors to Index Colors
« Reply #10 on: January 21, 2011, 08:53:59 AM »
with such a limited palette, I had to do several tests to get a good look. Perhaps the best was to use a scattering matrix to try to compensate for the lack of colors.
Who as designed the ACI palette? someone should send it to a desert island with a male gorilla.
Hasta pronto.See you soon.