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=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' )
from Microsoft.Office.Interop import Excel
from System.Runtime.InteropServices import Marshal

clr.AddReference('System.Drawing')
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
5 Likes

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

image

2 Likes

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?

Test02

https://gohtx.com/acadcolors.php