0

I try to unwrap UVs to every object, but after running the script, the UVs of the previous object and the latter object are associated.

I tried to deselect UVs and objects,but Didn't solve the problem,Here is my code:

import bpy

Num = len(bpy.data.collections['AutoUV'].objects)

for i in range(Num):

bpy.ops.object.select_all(action='DESELECT')

bpy.data.collections['AutoUV'].objects[i].select_set(True)

bpy.ops.object.editmode_toggle()

bpy.ops.uv.select_all(action='SELECT')

bpy.ops.uv.smart_project()

bpy.ops.uv.select_all(action='DESELECT')

bpy.ops.object.editmode_toggle()

```

Duarte Farrajota Ramos
  • 59,425
  • 39
  • 130
  • 187
DaTuDou
  • 41
  • 3
  • Hi and welcome. smart_project() operator works on the active object(s) in Edit Mode so you'd have to make each object the active one within the loop and call the operator, I have just updated Carlo's answer here: https://blender.stackexchange.com/a/103199/ Does this help? Also see: https://blender.stackexchange.com/questions/126577/blender-2-8-api-python-set-active-object – brockmann Nov 04 '21 at 09:15
  • thanks bpy.context.view_layer.objects.active = obj ,This is the crux of the matter. – DaTuDou Nov 05 '21 at 02:58
  • Glad I could help. If you'd like to unwrap all objects of a certain collection, just replace for obj in selection: by bpy.data.collections['Collection'].objects:. Cheers. – brockmann Nov 05 '21 at 07:23

0 Answers0