'How to get the layer color ( RGB value) in libreDwg
I 'm trying to get the color of every entity in the DWG file,One way to do this is to get the layer on which the entity is and then get the layer color
Dwg_Object_Entity* entity = dwg.object[i].tio.entity;
Dwg_Object_LAYER* layer = dwg_get_entity_layer(entity);
BITCODE_CMC color = layer->color;
But the RGB value and layer color are always different.(For example, the layer color is red and ByLayer,but the RGB value is 3271557130(0xC300 000A))
Here is the definition of BITCODE_CMC
typedef struct _dwg_color /* CmColor: R15 and earlier */
{
BITCODE_BSd index; /* <0: turned off. 0: BYBLOCK, 256: BYLAYER */
BITCODE_BS flag; /* 1: has name, 2: has book_name. */
BITCODE_BS raw; /* ENC only */
BITCODE_BL rgb; /* DXF 420 */
unsigned method; /* first byte of rgb:
0xc0 for ByLayer (also c3 and rgb of 0x100)
0xc1 for ByBlock (also c3 and rgb of 0)
0xc2 for entities (default), with names with an additional name flag RC,
0xc3 for truecolor,
0xc5 for foreground color
0xc8 for none (also c3 and rgb of 0x101)
*/
BITCODE_T name; /* DXF 430 */
BITCODE_T book_name; /* DXF 430, DXF: "book_name$name" */
// Entities only:
BITCODE_H handle;
BITCODE_BB alpha_type; /* 0 BYLAYER, 1 BYBLOCK, 3 alpha */
BITCODE_RC alpha; /* DXF 440. 0-255 */
} Dwg_Color;
typedef Dwg_Color BITCODE_CMC;
DXF 420-427: 32-bit integer value. When used with True Color; a 32-bit integer representing a 24-bit color value. The high-order byte (8 bits) is 0, the low-order byte an unsigned char holding the Blue value (0-255), then the Green value, and the next-to-high order byte is the Red Value. Convering this integer value to hexadecimal yields the following bit mask: 0x00RRGGBB. For example, a true color with Red==200, Green==100 and Blue==50 is 0x00C86432, and in DXF, in decimal,13132850
I'm not familiar with CAD, I think I used the wrong method to get the layer color but I don't know any other method to get the layer color at present
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
