Jump to content

Convert from index colours to true colours


djguinan

Recommended Posts

Does anyone have a lisp routine to globally convert entities from index colour to rgb(true colour)? I found a routine that does it the opposite way around.

Link to comment
Share on other sites

Thanks for the Welcome Tharwat:)

 

I have solid hatch entities in a drawing that I want to be True Colour rather then Index Colour. When in the Select Colour Dialoge box its the middle tab.

Link to comment
Share on other sites

Lee Mac

 

I only spotted your reply as I subbmitted a reply to Tharwat. That is exactly what I'm looking for, thanks very much:)

Link to comment
Share on other sites

Try this:

;; All to RGB  -  Lee Mac  -  www.lee-mac.com
;; Converts the ACI colours of all entities to the RGB TrueColor equivalent

(defun c:AlltoRGB ( / accm c e i s )
   (if
       (and
           (setq s (ssget "_:L"))
           (setq accm
               (vla-getinterfaceobject (vlax-get-acad-object)
                   (strcat "AutoCAD.AcCmColor." (substr (getvar 'ACADVER) 1 2))
               )
           )
       )
       (progn
           (repeat (setq i (sslength s))
               (setq e (entget (ssname s (setq i (1- i)))))
               (if (setq c (cdr (assoc 62 e)))
                   (progn
                       (vla-put-colorindex accm c)
                       (entmod
                           (append e
                               (list
                                   (cons 420
                                       (LM:RGB->True
                                           (vla-get-red   accm)
                                           (vla-get-green accm)
                                           (vla-get-blue  accm)
                                       )
                                   )
                               )
                           )
                       )
                   )
               )
           )
           (vlax-release-object accm)
       )
   )
   (princ)
)

;; RGB -> True - Lee Mac 2011
;; Args: r,g,b - Red,Green,Blue values

(defun LM:RGB->True ( r g b )
   (+
       (lsh (fix r) 16)
       (lsh (fix g)  8)
       (fix b)
   )
)

(vl-load-com) (princ)

It will change the colour of selected entities from the ACI colour to the RGB True Colour equivalent.

 

Note that it will change only those entities whose colour is not set to ByLayer (though these may be included if necessary by changing the respective layer colours).

 

More Colour Conversion functions.

Edited by Lee Mac
Link to comment
Share on other sites

Lee Mac

 

I only spotted your reply as I subbmitted a reply to Tharwat. That is exactly what I'm looking for, thanks very much:)

 

I modified it slightly and re-posted, please use the updated version above ^^

 

Thanks - glad it works for you.

Link to comment
Share on other sites

Thanks guys you've saved me alot of time. I'm a first time user of this site and I have to say I'm very impressed with the quick responses:)

Happy New Year

Link to comment
Share on other sites

Thanks guys you've saved me alot of time. I'm a first time user of this site and I have to say I'm very impressed with the quick responses:)

Happy New Year

 

You're very welcome djguinan, hope to see you back soon :)

Link to comment
Share on other sites

  • 6 years later...
Try this:

 

[color=GREEN];; All to RGB - Lee Mac - www.lee-mac.com[/color]

etc.

 

I found something strange while using this, I tested it in a color wheel dwg with index color swatches 40 through 49; colors 40(255,191,0) & 41(255,223,127) were correct; the other 8 were wrong; 42 became (204,153,0), should be (165,124,0); 43 became (204,178,102), should be (165,145,82); etc. Another interesting thing, the chart of colors on this site is different than both the results of your .lsp and what my tests on Autocad 2018 are: http://sub-atomic.com/~moses/acadcolors.html . Could it be that Autodesk did not space their color index evenly so a somewhat simple algorithm does not return values that line up with their index? BTW, it's a great macro!

Thanks,

R.L. Hamm

Link to comment
Share on other sites

  • 2 years later...
  • 2 months later...
On 1/6/2012 at 5:45 PM, Lee Mac said:

Try this: […]

It will change the colour of selected entities from the ACI colour to the RGB True Colour equivalent.

 

Note that it will change only those entities whose colour is not set to ByLayer (though these may be included if necessary by changing the respective layer colours).

 

More Colour Conversion functions.

Hi Lee Mac,

Thank you for your code.

I try it in acad 2021 but I get the error:

Quote

Command: APPLOAD
allToRBG.lsp successfully loaded.
Command: ; error: malformed list on input

when loading then

Quote

Command: ALLTORGB
Select objects: Specify opposite corner: 268 found
Select objects:
; error: no function definition: LM:RGB->TRUE

when running.

Can you please help?

Thank you

Link to comment
Share on other sites

7 hours ago, harinezumi said:

Hi Lee Mac,

Thank you for your code.

I try it in acad 2021 but I get the error:

when loading then

when running.

Can you please help?

Thank you

 

An update to the forum software some time ago had removed "8 )" from the LM:RGB->True function - I've now updated my earlier post to correct the code.

Link to comment
Share on other sites

  • 2 years later...
On 4/5/2021 at 6:13 PM, harinezumi said:

Hi Lee Mac,

Thank you for your code. I need Lisp for chenge layer color to RGB. Some layers already have RGB Color and all objekts by layer. Can you please help?

 

Link to comment
Share on other sites

Yes. I tried to understand this without success.

1.Where "defan c:"?

2.This will change the color of the layer or object?

Link to comment
Share on other sites

On 2/11/2024 at 10:36 AM, Slava said:

Yes. I tried to understand this without success.

1.Where "defan c:"?

2.This will change the color of the layer or object?

 

These are functions which may be called from other programs - they are not commands which can be executed at the command line.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...