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 df.name == 'Overview' or df.name == 'Keyplan': df.scale = 500000 for lyr in arcpy.mapping.ListLayers(mxd,"",df): if lyr.datasetName == 'blah': arcpy.mapping.RemoveLayer(df,lyr) lyr.replaceDataSource(r'\\directory','FILEGDB_WORKSPACE','FCName') arcpy.mapping.AddLayer(df,lyr,"TOP") arcpy.RefreshTOC() arcpy.RefreshActiveView() fullpath = os.path.join(fileDir,'ALTERED_' + fileName) mxd.saveACopy(fullpath) del mxd
I have had a look at http://forums.arcgis.com/threads/23803-issues-updating-data-source-via-arcpy.mapping?p=78411&viewfull=1 and used some of the tricks there, but I can't seem to make it work. Picture of layer datasource
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.