For loop moving on before executing code?

I’m trying to write a small code snippet that loops through all of the objects in my scene and sets the origin to geometry for each one. However, it only seems to execute for the last object in the scene - everything else remains untouched. The only thing I can think of is maybe the for loop is moving on to the next object before the origin_set() function has time to finish. Has anyone else seen this issue before?

import bpy

for obj in bpy.data.objects:   
    bpy.context.scene.objects.active = obj
    bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY')
    print("Setting origin: " + obj.name)

You need to select the object before running the origin_set operator^^

Isn’t that the point of this line? Or do I have to select it on top of that?

bpy.context.scene.objects.active = obj
bpy.context.scene.objects.active = obj

This command define the object as active but don’t select it as a mouse clic.
You need to select the object before using the origin_set operator.

obj.select = True

OHHH okay let me try that out. Will report back soon.

EDIT: You’re a genius, that did it. Thanks!