I am trying to create a script that makes a copy of the same feature class within the same file GDB by using the "copyfeatures" syntax which works fine. I am then trying to iterate through a list of .mxd's within a certain directory and find any .mxd with the feature class that I made a copy of and replace that feature class with the newer version or the copy of that feature class that I created earlier in the script.
The scripts seems to be running with the syntax below, the .mxd's are being saved and the script runs with no problems. However, the feature class in the .mxd is not updating.
import arcpy, os
arcpy.env.overwriteOutput = True
arcpy.env.workspace = r"C:\GISShare\jehmann\TESTING.gdb"
workspace = r"C:\TEST"
outdata_1 = r"C:\GISShare\jehmann\TESTING.gdb\JeffNotes_SHLs"
# Copy New Version of the Feature Classes
try:
arcpy.CopyFeatures_management('Notes_SHLs', 'JeffNotes_SHLs')
print "SHLs Feature Class Created Succesfully!"
except:
print "Failed to Create SHLs Feature Class"
for dirpath, dirnames, filenames in arcpy.da.Walk(workspace, topdown=True):
arcpy.env.workspace = dirpath
mxds = arcpy.ListFiles('*.mxd')
for filename in mxds:
print "------------------------------"
print filename
mxd = arcpy.mapping.MapDocument(os.path.join(dirpath, filename))
for layer in arcpy.mapping.ListLayers(mxd):
if layer.supports("DATASOURCE"):
print "{} -> {}".format(layer.name, layer.dataSource)
if '%Notes_SHLs%' in layer.dataSource:
layer.replaceDataSource(layer.dataSource, "FILEGDB_WORKSPACE", outdata_1)
mxd.save()
I think it has something to do with how I have the layer.replaceDataSource set up?
print "{} -> {}".format(layer.name, layer.dataSource)
?if '%Notes_SHLs%' in layer.dataSource:
block? Add a print inside that block to test