How to change the positioning of Drupal blocks when a theme is enabled? I am developing a Drupal 7 theme. I want to change the position of the blocks when a user set my theme as default.

In my theme the main menu is positioned in left sidebar. Suppose the current theme of the user has main menu in the header block, when a user enables my theme, the main menu should go to the left sidebar. 

Basically I want to position the block using code when my theme is set as default. 

Any way to implement this?
Only using Drupal core

Investigate the 'current theme of the user', to identify the 'region name' where the 'header block' (which contains the main menu) is positioned. Let's say that region is called "HeaderRegion".

Then in your own theme, make sure to create a region with the exact same name (like "HeaderRegion"), and position that region in the area that corresponds with what you describe as "left sidebar".

With this approach, the "main menu" will be shown in both themes in the block that is positioned in the "HeaderRegion"-region. And the actual theme that is selected will determine if it will be shown in the header (if using the current theme) or in the left sidebar (if using your own theme). Note: a "left sidebar" with a region name like "HeaderRegion" will sound a bit confusing, but that's a way to make it work ... (and maybe that region name in your current theme has a less confusing name, so you might be lucky and not suffer that confusion ...).

Using a contributed module

By using the Themekey module, you can implement content, user, or role -specific themes.

So if you can come up with the appropriate set of theme variations (which would differ by the location of your theme regions in which the blocks are displayed), this could be a solution that could work.