Search code examples
c#autocadautocad-plugin

Autocad Developer: how to get Object Color in RGB mode by using C#


enter image description here

Hi All, I would like to get the Object Color in Properties in RGB Mode. I have try the code like string cecolor = acDocComObj.GetVariable("CECOLOR"); but this does not return the in TrueColor. Anyone got idea on how to do it?


Solution

  • The reply I gave on Autodesk discussion group.

            AcadAcCmColor color = new AcadAcCmColor();
            int index = 0;
            if (colorName.ToUpper() == "BYBLOCK")
            {
                color.ColorIndex = AcColor.acByBlock;
            }
            else if (colorName.ToUpper() == "BYLAYER")
            {
                color.ColorIndex = AcColor.acByLayer;
            }
            else if (int.TryParse(colorName, out index))
            {
                color.ColorIndex = (AcColor)index;
            }
            else if (colorName.ToUpper().StartsWith("RGB:"))
            {
                string[] rgb = colorName.Substring(4).Split(',');
                color.SetRGB(int.Parse(rgb[0]), int.Parse(rgb[1]), int.Parse(rgb[2]));
            }
            else
            {
                string[] bookColor = colorName.Split('$');
                color.SetColorBookColor(bookColor[0], bookColor[1]);
            }