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:
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
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 @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?
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.)
@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.