Can you please take a look at this example and let me know how to I can replace Data Source data of a layer in a saved mxd map (Fuse) to a layer called SDEElectric.DBO.Fuse which is in an enterprise geodatabase through database connection
I tried this code but it didnt work
import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\GIS\Maps\Electric.mxd")
src =r"C:\Users\xxx\AppData\Roaming\ESRI\Desktop10.4\ArcCatalog\SDEElectric.sde\SDEElectric.DBO.Dataset\SDEElectric.DBO.Fuse"
df = arcpy.mapping.ListDataFrames(mxd, "")[0]
for lyr in arcpy.mapping.ListLayers(mxd, "", df):
if lyr.name == "Fuse":
lyr.replaceDataSource(src, "FILEGDB_WORKSPACE", "")
mxd.save()
del mxd
print "done"
Not a Python expert, but
lyr.replaceDataSource(src, "FILEGDB_WORKSPACE", "")
Shouldn't the above reflect an Enterprise gdb, like below:
lyr.replaceDataSource(src, "SDE_WORKSPACE", "")
If the above doesn't help, share the errors you receive and that may also help someone to provide an answer....
Thanks Asrujit SenGupta
but still getting same error
What errors do you receive?
you may want to look at /blogs/myAlaskaGIS/2015/08/31/python-addin-for-data-inventory-and-broken-link-repair?sr=search&searc... to see samples of how I view and replace sources in mxd. It's based mainly on broken-links, so may not work for you, but just in case.
Thanks Rebecca, I already spend some time there but it was not really helpful as it mainly focus was on fixing broken links