We have many mxd files by different users and I want to change one SDE feature class name in all those mxd files without changing SDE connections. As a test, I thought this script would work, but I always get "Unable to change name" exception. Where am I wrong?
mxd = arcpy.mapping.MapDocument(r"L:\users\guana\test_fc_rename.mxd")
for df in arcpy.mapping.ListDataFrames(mxd):
for lyr in arcpy.mapping.ListLayers(mxd,"",df):
if lyr.supports("DATASOURCE"):
if lyr.dataSource.find("SDE_GOM.LEXCO_LEASE") <> -1:
(str1,str2,fname) = lyr.dataSource.split("\\")
sdecon = str1 + "\\" + str2
print "sdecon = " + sdecon
try:
lyr.replaceDataSource(sdecon,"SDE_WORKSPACE","SDE_GOM.LEASE_LEXCO")
except:
print "Unable to change name"