ACI Color to RGB

Hi, I am looking for solution how to create new AutoCAD Layer with color based on excel cell color.
I use Dynamo for Civil 3D. I found this solution here Read Excel Cell Fill Color - #2 by cgartland I only changed code little bit so I can get ACI color, see picture

Now I do not know how to convert ACI color from ColorIndex method to RGB to set new layers colors.
Is here anyone who has any experience with Python? Here are some links which may help:

  1. AutoCAD Color Index RGB Equivalents

  2. Index color versus true color and how to use AcCmEntityColor::colorMethod - AutoCAD DevBlog

Hello @Drbohlav
instead of trying to convert ColorIndex to Rgb you can use Interior.Color and ColorTranslator to get RGB values

import clr
import System
from System.Collections.Generic import List
clr.AddReferenceByName('Microsoft.Office.Interop.Excel, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c' )
from Microsoft.Office.Interop import Excel
from System.Runtime.InteropServices import Marshal

from System.Drawing import Color, ColorTranslator

def getRGBfromIntColor(intColor):
	colorGDI = ColorTranslator.FromOle(intColor)
	return 	colorGDI.R, colorGDI.G, colorGDI.B

rgbColor = []
ex = System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application")
ex.Visible = True
workbook = ex.ActiveWorkbook
ws = ex.ActiveSheet
myrange = ws.Range[ws.Cells(1, 1), ws.Cells(10, 1)]

#setColor by Interior ColorIndex (just for example)
i = 10
for rx in myrange:
	rx.Interior.ColorIndex = i
	i += 1
#get Rgb by Interior Color and ColorTranslator 
for rx in myrange:
	r, g, b = getRGBfromIntColor(rx.Interior.Color)
	rgbColor.append([r, g, b])
OUT = rgbColor

Hello @c.poupin, thank you for your solution. I have one question for all. Do you think it is possible set color in excel by index (ACI) and then import it to Civil 3D as Layer with color, which is set by this index?
I attached picture where I created layer TEST manually.

Hello @Drbohlav
you can try to use the LookUpAci() and/or LookUpRgb() methods (ObjectARX ) to convert ACI to RGB

here an example

color_index = Autodesk.AutoCAD.Colors.EntityColor.LookUpAci(255, 255, 0)
RGBint = Autodesk.AutoCAD.Colors.EntityColor.LookUpRgb(color_index )
Blue =  RGBint & 255
Green = (RGBint >> 8) & 255
Red =   (RGBint >> 16) & 255
rgb = [Red, Green, Blue]
OUT = color_index, rgb



Hello @c.poupin, it is little bit confusing for me now. See pictures please and focus your attention on color index 254 please. RGB is different on pictures. Is here anyone who knows more about AutoCAD colors please?


Sorry for bumping this but I ran into a similar problem (a bit easier, even) and just can’t get it to work.

I want my ACI as an input and the RGB value as an output, so for example:
106 ==> [0,76,19]

I’ve tried

RGBint = Autodesk.AutoCAD.Colors.EntityColor.LookUpRgb(color_index)

but I’m always getting this error

Warnung:TypeError : No method matches given arguments for OnExit: (<class ‘Autodesk.AutoCAD.ApplicationServices.DocumentLock’>

Is there an import I’m overlooking?

Any help would be appreciated!

Attach an example of the code you are working on
let’s try with you

as a @Drbohlav has mentioned, Autocad seems to have its own custom internal color table

credit @chuongpqvn for Ipy console


Thanks for your responses!
I got it working, as per usual I simply messed up the syntax - I attached my script (which is a word for word copy of @Drbohlav) for future reference.

I’m now facing the same problem as everyone else: the internal colors don’t match the correct RGB-values.

I really don’t know how to continue from here - I thought RGB was bulletproof (as in replicable) but it seems it’s impossible to get the actual, correct RGB-color of an Autocad-CI-object?
(My goal is to extract mtexts with position and color and have them “redrawn” in another software where I can only set RGB-color values.)

ACI2RGB.dyn (7.3 KB)

I will add this to the codebase example, thanks :kissing_closed_eyes:

1 Like

@pumpaij There appears to be ways to extract the RGB from an ACI colour … but you may not end up with the final colour in the end product, because of the pen table colours that get applied to ACI colours during plotting, or in previews. RGB’s aren’t translated by the pen table.

@c.poupin @chuongpqvn
I see very interesting this form of console to test the python codes could you tell me if you were as kind as I can get it

You can find here

(from @chuongpqvn )

1 Like