.NET

Reply
Valued Contributor
mario.rosenbohm
Posts: 56
Registered: ‎12-06-2006
Message 1 of 4 (700 Views)

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

700 Views, 3 Replies
02-13-2013 05:58 PM

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

Valued Mentor
AubelecBE
Posts: 394
Registered: ‎01-27-2010
Message 2 of 4 (689 Views)

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

02-14-2013 04:25 AM 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.

 

 

 

*Expert Elite*
Alfred.NESWADBA
Posts: 9,400
Registered: ‎06-29-2007
Message 3 of 4 (683 Views)

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

02-14-2013 04:44 AM in reply to: mario.rosenbohm

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
-------------------------------------------------------------------------
Valued Contributor
mario.rosenbohm
Posts: 56
Registered: ‎12-06-2006
Message 4 of 4 (663 Views)

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

02-14-2013 12:27 PM in reply to: mario.rosenbohm

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

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!