Autodesk.AutoCAD.Colors.EntityColor.LookUpAci result is wrong

Autodesk.AutoCAD.Colors.EntityColor.LookUpAci result is wrong

Anonymous
Not applicable
2,544 Views
3 Replies
Message 1 of 4

Autodesk.AutoCAD.Colors.EntityColor.LookUpAci result is wrong

Anonymous
Not applicable

Hello,

 

i would get the AutoCAD ColorIndex from RGB.

 

The RGB Color is 165,41,0 is the korrekt RGB from Index 22, but the

"Autodesk.AutoCAD.Colors.EntityColor.LookUpAci" result is Index 27 (RGB 127,31,0)

 

why?

 

regards Mario

0 Likes
2,545 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable

Here a code for converting. (I use it for convert color from the Dialog Color in autocad :

Dim fenetre As New Autodesk.AutoCAD.Windows.ColorDialog
            fenetre.Color = Autodesk.AutoCAD.Colors.Color.FromRgb(Red as byte,green as byte, blue as byte)
            fenetre.IncludeByBlockByLayer = False
            If fenetre.ShowDialog() = Windows.Forms.DialogResult.OK Then
                Dim CouleurR As Byte
                Dim CouleurB As Byte
                Dim CouleurV As Byte

                If fenetre.Color.IsByAci = False Then
                    CouleurR = fenetre.Color.Red
                    CouleurB = fenetre.Color.Blue
                    CouleurV = fenetre.Color.Green
                Else
                    'conversion 
                    'Get the rgb values from the index
                    Dim colIndex As Integer
                    colIndex = fenetre.Color.ColorIndex
                    Dim bytes() As Byte = BitConverter.GetBytes( _
                            Autodesk.AutoCAD.Colors.EntityColor.LookUpRgb(colIndex))

                    CouleurR = bytes(0)
                    CouleurB = bytes(2)
                    CouleurV = bytes(1)
                    
                End If
                ' here uour code for use the var CouleurR, ..B, ...V

            End If

 fenetre.Color = Autodesk.AutoCAD.Colors.Color.FromRgb(Red as byte,green as byte, blue as byte)

--> replace Red, green and blue  with your data.

 

 

 

0 Likes
Message 3 of 4

Alfred.NESWADBA
Consultant
Consultant

Hi Mario,

 

the only thing I know with differences between calculation of ACI <> TrueColor is that the background of AutoCAD changes the result of the calculation. So it's different for AutoCAD if you are working with black of white AutoCAD-background.

 

I'm not sure if this special function is also depending on the background, but at least you might try it both states of background just to verify it (on CAD-de there was also such a thread if you want to search there).

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 4 of 4

Anonymous
Not applicable

Hello,

 

i make a litle workaround and this get the korrekt ACI-Color

 

        public static Autodesk.AutoCAD.Colors.Color getAutoCADColorFromMediaColor(System.Windows.Media.Color defaultColor)
        {
            if (defaultColor != null)
            {
                Autodesk.AutoCAD.Colors.Color colorIndex;
                Autodesk.AutoCAD.Colors.Color colorARGB = Autodesk.AutoCAD.Colors.Color.FromColor(System.Drawing.Color.FromArgb(defaultColor.A, 
                                                          defaultColor.R, defaultColor.G, defaultColor.B));
                for (byte i = 0; i <= 255; i++)
                {
                    colorIndex = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByAci, i);
                    if (colorIndex.ColorValue.A == colorARGB.ColorValue.A)
                    {
                        if (colorIndex.ColorValue.R == colorARGB.ColorValue.R)
                        {
                            if (colorIndex.ColorValue.G == colorARGB.ColorValue.G)
                            {
                                if (colorIndex.ColorValue.B == colorARGB.ColorValue.B)
                                {
                                    return colorIndex;
                                }
                            }
                        }
                    }
                }
                return colorARGB;                     
            }
            else
                return Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.None, 7);
        }

 regards Mario