.NET

.NET

Reply
Valued Contributor
56 Posts
4 Kudos
Registered: ‎12-06-2006
Post 1 of 4

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

742 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
411 Posts
28 Kudos
Registered: ‎01-27-2010
Post 2 of 4

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*
9,817 Posts
1,211 Kudos
Registered: ‎06-29-2007
Post 3 of 4

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
56 Posts
4 Kudos
Registered: ‎12-06-2006
Post 4 of 4

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 interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!