Looping Through Layers in Mxd and Saving Mxd Changes Extent

4504
23
05-21-2013 02:14 PM
MichaelVolz
Esteemed Contributor
To All Python Users:

I have a script that loops through all the layers in an mxd and then saves the mxd.  I have found that when I open up the saved mxd the extent of the map in the data view has changed even though I did not write code for the extent to change.  Has anyone come across this phenomenon before?

The problem I am finding is that the layout view, that could be setup for a print job, has changed.  Now the user has to go back and fix the extent for the layout to be printed correctly.  I am eventually looking to run this script on many mxds in batch and I do not want to disrupt all the mxds where the endusers need to go back and fix the extent.

Why would the map extent change if all I am doing is looping through the layers in a python script?
Tags (2)
0 Kudos
23 Replies
LorindaGilbert
Frequent Contributor
Not quite sure how/why it does it, but I have in many mxd's the workspace is referencing a database connection string that is no longer in service, you see this by exposing the workspace path or using ArcCatalog's repair data source.  However, we are getting the data due to the last time that we went through this exercise (there have been at least 4) there were no nice scripts out there to do bulk updates (and the ArcCatalog repair datasource failed miserably), so the repair data source in ArcMap was used, the mxd saved and we went on our merry way.

Fast forward to today, our mxd's still show these long outdated workspace paths but source the current database on the old server.  In Python, you can only read the service properties but not update them (sure would be nice to be able to update the service properties, hint, hint ESRI) - so my workaround was to update the workspace path no matter what it said (of which some were pointing to directories that were created on our XP machines - we are now on Win 7; so you know those directories no longer exist; some on my machine were also pointing to a directory from someone else's XP machine that is also long gone!), but rely only on the sde service type and the database name that the service property said was being sourced to update only the one changing.  Interestingly, all of our database iterations have had the same name, just different server names, so it happens to work out.  In the future if we change db name as well as server, it may not work.
0 Kudos
MichaelVolz
Esteemed Contributor
"Fast forward to today, our mxd's still show these long outdated workspace paths but source the current database on the old server." Can you post a screenshot of this and explain the issue?


Also, have you ever tried running these mxds through MxdDoctor to see if there is corruption in these mxds?
0 Kudos
T__WayneWhitley
Honored Contributor
I have a vague memory of having problems resolving the host name after writing a script that worked fine before my db server was shut down......I do recall, the script worked beautifully to 're-source' all my db params to my new database server, basically an updated SQL Server clone.

This seemed to help, temporarily changing the hosts file:
http://www.howtogeek.com/howto/27350/beginner-geek-how-to-edit-your-hosts-file/

...for what it is worth.  I just remember not being very well pleased with that solution, that it was still excruciatingly slow, but it at least got me out of the epic fail mode.  If I remember correctly, I think a more timely solution for users was that my IT 'resurrected' my old server to give users time to execute the script.  Funny how they seemed to anticipate that it could be a headache!

Don't anticipate that happening again, but would sure like to know if there's a more effective solution.  ...I have some ideas, but certainly I'll try to leave it to the network guys, if it comes to that again!

Thanks for contributing, I'll be looking in for that 'perfect' solution.

Enjoy,
Wayne

EDIT:
Sorry...this is potentially relevant info - I encountered this puzzling problem in my upgrade from 9.3.1 to 10.0 SP5 onto a new server.  User Desktops were already at 10.0... so I really don't know if the problem will manifest in some form on my network with 10.1 or 10.2.
0 Kudos
MichaelVolz
Esteemed Contributor
I have just added an post to the ideas website (ideas.arcgis.com) for ESRI to allow the option of either embedding the SDE connection information inside mxds or have the mxd refer to the .sde files outside the mxd for SDE connection information.  In this way, if you rely on the .sde files, then you would only need to update that information instead of the mxds.  Please promote this post if you like this idea.
0 Kudos