You are in the wrong context. Your context is in Object Mode but you need to be in Edit Mode. Here is the working script:
import bpy
bpy.ops.object.select_all(action='DESELECT')
selected_objects = [bpy.data.objects['Cube'], bpy.data.objects['Suzanne']]
for obj in selected_objects:
obj.select_set(True)
area_type = 'VIEW_3D'
areas = [area for area in bpy.context.window.screen.areas if area.type == area_type]
if len(areas) <= 0:
raise Exception(f"Make sure an Area of type {area_type} is open or visible in your screen!")
with bpy.context.temp_override(
window=bpy.context.window,
area=areas[0],
regions=[region for region in areas[0].regions if region.type == 'WINDOW'][0],
screen=bpy.context.window.screen
):
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.uv.smart_project(angle_limit=1.15192, margin_method='SCALED', island_margin=0, area_weight=0, correct_aspect=True, scale_to_bounds=False)
EDIT: Oh we don't even need to do any context overrides still works:
import bpy
bpy.ops.object.select_all(action='DESELECT')
selected_objects = [bpy.data.objects['Cube'], bpy.data.objects['Suzanne']]
for obj in selected_objects:
obj.select_set(True)
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.uv.smart_project(angle_limit=1.15192, margin_method='SCALED', island_margin=0, area_weight=0, correct_aspect=True, scale_to_bounds=False)
override=context.copy()i think is deprecated. blender.stackexchange.com/questions/6101/… $\endgroup$Editmode, but I want it inObjectmode. I also tried usingoverride['mode'] = 'EDIT_MESH'$\endgroup$override = context.copy()that is deprecated. useoverride = {}. that will work in edit mode. bmesh doesnt have a direct uv unwrap method. I don't think you can avoid going into Edit mode. $\endgroup$