简体   繁体   中英

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

在此处输入图片说明

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?

For any Entity in AutoCAD (eg line, circle, block, etc), you can use the .Color property (for .NET in-process API):

Entity ent = // get the entity here;
Autodesk.AutoCAD.Colors.Color c = ent.Color;
int[] rgb = new int[] { c.Red, c.Green, c.Blue };

As you mentioned out-of-process COM/ActiveX, you can try something similar:

AcadEntity ent = // get the entity here;
int[] rgb = new int[] { ent.TrueColor.Red, ent.TrueColor.Green, ent.TrueColor.Blue };

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]);
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM