Scripting error using view3d
Some commands require a specific context. For instance, to use the view3d commands you must switch to the VIEW_3D context first. This should do it:


import bpy
#switch context
previous_context = bpy.context.area.type
bpy.context.area.type = 'VIEW_3D'

#do stuff
bpy.ops.view3d.snap_cursor_to_selected()
bpy.ops.object.editmode_toggle()
bpy.ops.object.origin_set(type='ORIGIN_CURSOR')
bpy.ops.view3d.snap_cursor_to_center()
bpy.ops.view3d.snap_selected_to_cursor(use_offset=False)
bpy.ops.object.editmode_toggle()

#restore previous context
bpy.context.area.type = previous_context