Sorry, I asked similar question on another post.
Finally I made a little script which works well in my case
Here it’s the link to the other post :
And here is the script :
import bpy
sel_objs = [obj for obj in bpy.context.selected_objects if obj.type == 'MESH']
for obj in sel_objs:
obj.select_set(False)
while len(sel_objs) >= 1:
obj1 = sel_objs.pop()
obj1.select_set(True)
bpy.context.view_layer.objects.active = obj1
bpy.context.scene.tool_settings.use_transform_data_origin = False
bpy.context.scene.transform_orientation_slots[0].type = 'NORMAL'
bpy.ops.object.mode_set( mode = 'EDIT' )
bpy.ops.mesh.select_mode( type = 'FACE' )
bpy.ops.mesh.select_all( action = 'DESELECT' )
bpy.ops.mesh.select_face_by_sides(number=4, type='GREATER')
bpy.ops.transform.create_orientation(name='tmp', use_view=False, use=False, overwrite=True)
bpy.context.scene.transform_orientation_slots[0].type = 'tmp'
bpy.ops.object.mode_set( mode = 'OBJECT' )
bpy.context.scene.tool_settings.use_transform_data_origin = True
bpy.ops.transform.transform(mode='ALIGN', orient_type='tmp', orient_matrix_type='tmp')
bpy.context.scene.tool_settings.use_transform_data_origin = False
bpy.context.scene.transform_orientation_slots[0].type = 'LOCAL'
obj1.select_set(False)