Jump to content
djguinan

Convert from index colours to true colours

Recommended Posts

djguinan

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.

Share this post


Link to post
Share on other sites
Tharwat

Welcome to the forum :)

 

What do you mean by the rgb colour ? Does it mean ByLayer ?

Share this post


Link to post
Share on other sites
djguinan

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.

Share this post


Link to post
Share on other sites
djguinan

No Sorry, if it helps this lisp is the opposite of what I want to do.

rgb2aci.lsp

Share this post


Link to post
Share on other sites
djguinan

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:)

Share this post


Link to post
Share on other sites
Lee Mac

Try this:

 

[color=GREEN];; All to RGB  -  Lee Mac  -  www.lee-mac.com[/color]
[color=GREEN];; Converts the ACI colours of all entities to the RGB TrueColor equivalent[/color]

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

[color=GREEN];; RGB -> True - Lee Mac 2011[/color]
[color=GREEN];; Args: r,g,b - Red,Green,Blue values[/color]

([color=BLUE]defun[/color] LM:RGB->True ( r g b )
   ([color=BLUE]+[/color]
       ([color=BLUE]lsh[/color] ([color=BLUE]fix[/color] r) 16)
       ([color=BLUE]lsh[/color] ([color=BLUE]fix[/color] g)  
       ([color=BLUE]fix[/color] b)
   )
)

([color=BLUE]vl-load-com[/color]) ([color=BLUE]princ[/color])

 

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.

Share this post


Link to post
Share on other sites
Lee Mac
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.

Share this post


Link to post
Share on other sites
djguinan

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

Share this post


Link to post
Share on other sites
Lee Mac
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 :)

Share this post


Link to post
Share on other sites
rhgrafix
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

Share this post


Link to post
Share on other sites
Roy_043

@rhgrafix:

I am afraid you are using information that is obsolete. You can verify the RGB values of ACI colors by means of a screenshot.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×