Obtain the RGB color value from an AcDbEntity using ObjectARX and RealDWG

by Fenton Webb

Here’s how to obtain the RGB value from an already AcDb::kOpenForRead AcDbEntity.

static COLORREF GetRGBFromEntity( AcDbEntity *ent )    {      COLORREF colorRef = RGB(255, 255, 255);      AcCmColor Color = ent->color();      AcCmEntityColor::ColorMethod ColorMethod = Color.colorMethod();           switch(ColorMethod)      {      case AcCmEntityColor::kByACI:        {                    long acirgb, r,g,b;          acirgb = AcCmEntityColor::lookUpRGB(Color.colorIndex());               b = ( acirgb & 0xff00L );           g = ( acirgb & 0xff00L ) >> 8;           r = acirgb >> 16;               colorRef = RGB( r, g, b);            break;             }      }      
return colorRef;    }

Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading