0
$\begingroup$

I want to batch packing every single object's UV. But the script can't go throw everyone. After packing one object, it stopped with no error. What's wrong?

(I've already did Cube Projection for all objects beforehand.)

import bpy

for obj in bpy.context.selected_objects:
    bpy.ops.object.select_all(action='DESELECT')
    obj.select_set(True)

    bpy.ops.object.mode_set(mode = 'EDIT')
    bpy.ops.mesh.select_all(action='SELECT')
    bpy.ops.uv.pack_islands(margin=0.001)
    bpy.ops.object.mode_set(mode = 'OBJECT')
    

enter image description here

$\endgroup$

1 Answer 1

0
$\begingroup$

Due to some silly mistakes. This one works.

import bpy

objs = bpy.context.selected_objects

for obj in objs:
    bpy.ops.object.select_all(action='DESELECT')
    obj.select_set(True)
    bpy.context.view_layer.objects.active = obj

    bpy.ops.object.mode_set(mode='EDIT')
    bpy.ops.mesh.select_all(action='SELECT')
    bpy.ops.uv.pack_islands(margin=0.001)
    bpy.ops.object.mode_set(mode='OBJECT')
$\endgroup$

You must log in to answer this question.

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