What's wrong with my batch script? 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')
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')