0
$\begingroup$

I was looking through the blender 2.8 bees but I can't find anything, I've seen on some forums using the bmesh module, but I'm not sure it's the right way.

I could use the operator but I already know that on large scenes inserting the ops in a "for" loop would become very slow.

bpy.ops.mesh.uv_texture_add()

$\endgroup$
4
  • $\begingroup$ You just want to add a UV map, not generating it in a particular way? $\endgroup$
    – lemon
    Aug 28, 2019 at 6:18
  • $\begingroup$ This is a good question, I noticed that by default it spreads the map on every single polygon, I would like to understand how to do this, it would also be good to understand how to simulate a "Smart uv" I didn't find much about it $\endgroup$
    – Noob Cat
    Aug 28, 2019 at 11:50
  • 1
    $\begingroup$ I don't think smart uv corresponds to API which is not bpy.ops (to verify). But just for texture_add, you can obj.data.uv_layers.new(name="UvMap") $\endgroup$
    – lemon
    Aug 28, 2019 at 11:57
  • $\begingroup$ @lemon This is exactly what I was looking for, you should enter it as an answer, thank you very much $\endgroup$
    – Noob Cat
    Aug 28, 2019 at 13:21

2 Answers 2

2
$\begingroup$

A low-level alternative to bpy.ops.mesh.uv_texture_add() is obj.data.uv_layers.new(name="UvMap"). This way you don't need to set the operator context.

Though, it will not allow complex unwrapping such as Smart UV Project.

$\endgroup$
0
$\begingroup$

Extending the answer above further, here is how you can add a new uv_layer to all meshes in the scene and select it as the active uvmap.

import bpy

new_uvmap_name = 'UVCombined'

for mesh in bpy.data.meshes:
    if new_uvmap_name not in mesh.uv_layers:
        new_uv_map = mesh.uv_layers.new(name=new_uvmap_name)
        new_uv_map.active = True
    
    
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .