How would I test if an object object has a uv map from Python?
Run some code in this case, otherwise throw an error.
Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It only takes a minute to sign up.Sign up to join this community
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")
uv_layers can be replaced by
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.