6
$\begingroup$

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

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

$\endgroup$
7
$\begingroup$

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.