Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm attempting to replace a datasource in an outline map frame using ArcPy. The rest of the script seems to run OK, but after the script has run the datasource the datasource of that layer shows an error. A section of my code is below:

for df in arcpy.mapping.ListDataFrames(mxd):
    if == 'Overview' or == 'Keyplan':
        df.scale = 500000
    for lyr in arcpy.mapping.ListLayers(mxd,"",df):
        if lyr.datasetName == 'blah':

fullpath = os.path.join(fileDir,'ALTERED_' + fileName)
del mxd

I have had a look at and used some of the tricks there, but I can't seem to make it work. Picture of layer datasource

before: enter image description here

and after enter image description here

You'll see it has the correct layer name, but no actual layer. Any ideas what could be causing this. I thought at one point relative paths, but apparently they do not matter when using UNC paths, as I am.

This appears to work when I do it in ArcGIS itself using the "CURRENT" map, so pretty sure it's not a pathname error.

Any ideas?

share|improve this question
up vote 2 down vote accepted

This seemed to be an issue with relative paths. The mxd that I was trying to update was stored as Relative Paths in Document Properties. Once this was unchecked, the script worked as expected (without the delay).

So you can check each mxd manually, but given that this is a script, that slightly defeats the purpose. Unfortunately though ArcPy doesn't expose an API to change this particular setting (at least in 10.0).

So I have created a python script that uses ArcObjects to do it, with a lot of help from other people on the forum and outside. It needs an external library installed, but it is conceptually very simple. It can be found at

There may also have been an issue with long path names - if you are still having problems try copying to a local directory (I was on a network) and running the script from there. I found I then had to re-run the ArcObjects script to change the relative path setting, because mysteriously the ReplaceDataSource() method turned this on in the copied MXD. This method has got really strange behaviour, and from what I've seen, it doesn't seem to be fixed in 10.1

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.