True ColorΒΆ

The support for true color was added to the DXF file format in revision R2004. The true color value has three components red, green and blue in the range from 0 to 255 and is stored as a 24-bit value in the DXF namespace as true_color attribute and looks like this 0xRRGGBB as hex value. For a more easy usage all graphical entities support the rgb property to get and set the true color as (r, g, b) tuples where the components must be in the range from 0 to 255.

import ezdxf

doc =
msp = doc.modelspace()
line = msp.add_line((0, 0), (10, 0))
line.rgb = (255, 128, 32)

The true color value has higher precedence than the AutoCAD Color Index (ACI) value, if the attributes color and the true_color are present the entity will be rendered with the true color value.

The true color value has the advantage that it defines the color absolutely and unambiguously, no unexpected overwriting is possible. The representation of the color is fixed and only depends on the calibration of the output medium: