2
$\begingroup$

I want to create a script that checks if the selected mesh has an UV Channel, if not it does a Smart UV Project.

$\endgroup$

1 Answer 1

2
$\begingroup$

This will do the trick:

import bpy

# Check if active object has any UV layers
if not len( bpy.context.object.data.uv_layers ):
    bpy.ops.uv.smart_project() # Perform smart UV projection 
$\endgroup$
2
  • $\begingroup$ Thank you! Also we don't need to enter in edit mode to do a smart project with scripts. $\endgroup$ Jul 22, 2017 at 13:04
  • $\begingroup$ Well I'll be, you're right - I'll fix the code above. $\endgroup$
    – TLousky
    Jul 22, 2017 at 13:06

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.