how to set origin to center ?

tried this little script to do
Ctrl- A for each ob
but the orgine center does not seems to work

can anyone help to correct this



	
import bpy

scene = bpy.context.scene


for obj in bpy.context.scene.objects:
	if obj.type=="MESH":
		print ('ob name=',obj.name)
		bpy.ops.object.transform_apply(location=True, rotation=True, scale=True)
	
		apply_modifiers = True
#		modifiedmesh = object.to_mesh(scene,apply_modifiers,'PREVIEW')
	
scene.update()


thanks fro any feedback
happy bl

In order to see what operator you want to use, you can use it as normal and read it’s name in the information window.

In this case I used the one to set the origin to the center of mass:


import bpy


def origin_to_center():
    
    # deselect all of the objects
    bpy.ops.object.select_all(action='DESELECT')


    # loop all scene objects    
    for obj in bpy.context.scene.objects:
        
        # get the meshes
        if obj.type=="MESH":
            
            print(obj)
            
            # select / reset origin / deselect
            obj.select = True
            bpy.ops.object.origin_set(type='ORIGIN_CENTER_OF_MASS')
            obj.select = False
            
origin_to_center()

will try it !

what is the difference between center of mass and mesh origin ?

any doc describing the different origins ?

I also used the active ob instead of the select ob
not certain if it is equivalent !

thanks happy bl