I have many map documents that point to a hosted imagery service layer that has changed names.
I would like to write an ArcPy script that will replace the data sources of service layers that have changed names. So far I have tried the following from the Python window, without success (assuming the only layer in the MXD is the service layer):
mxd = arcpy.mapping.MapDocument("CURRENT")
lyr = arcpy.mapping.ListLayers(mxd)[0]
sourceURL = lyr.serviceProperties["URL"]
arcpy.AddMessage("Source URL: {0}".format(sourceURL))
destURL = "https:\path\to\image\service"
arcpy.AddMessage("Destination URL: {0}".format(destURL))
lyr.findAndReplaceWorkspacePath(sourceURL, destURL)
arcpy.RefreshTOC()
arcpy.RefreshActiveView()
mxd.save()
connectionProperties
is a dictionary with your new values? – Midavalo♦ Jun 30 '16 at 18:31destURL
variable to be more generic. – RyanKDalton Jun 30 '16 at 19:35