.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

3 REPLIES 3
Reply
Message 1 of 4
mario.rosenbohm
2073 Views, 3 Replies

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

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

3 REPLIES 3
Message 2 of 4
AubelecBE
in reply to: mario.rosenbohm

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.

 

 

 

Message 3 of 4

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
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 4 of 4

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost