# How to check if an object has a uvmap with python?

How would I test if an object object has a uv map from Python?

Run some code in this case, otherwise throw an error.

In this case you'll need to check if the objects mesh data has any UV layers. This works for vertex colors too.

import bpy
if bpy.context.object.data.uv_layers:
print("We have UV's")
else:
# if this runs from an operator, you may want to report an error instead.
raise Exception("Missing UV's")


Where uv_layers can be replaced by vertex_colors, materials... or any other sequence you want to check is empty or not.

Note: In Python you could check: if len(bpy.context.object.data.uv_layers) > 0: however there is no need, since all sequences will evaluate to False when empty, infact, this is slower in some cases since counting all items can be avoided when we only need to check if its empty.