Home/ Reference/ Pitfalls

HexValue casing is inconsistent

Normalize with .upper() before comparing, or your color filter quietly misses things.

Symptom

HexValue casing is inconsistent

Notes

Normalize with .upper() before comparing, or your color filter quietly misses things.

Python example (runnable)

Requires pywin32. The example assumes app / doc / page / layer are already connected. See Connection & Init
Python
shape = app.ActiveSelectionRange(1)

# HexValue casing varies, so upper() before comparing
hex_now = (shape.Fill.UniformColor.HexValue or "").upper()
YELLOW = "#FFFF00"

print("Now: ", hex_now, " is yellow: ", hex_now == YELLOW)

About this section: Pitfalls

Pitfalls — errors that fail without raising.

Other entries in this section