I have a very simple script meant to fix broken map layers by replacing the data source. After talking to an ESRI tech he was saying it could be a problem with the IDE I'm using, or something possibly with the version of Python. I'm using PyScripter which is pointing to Python 2.7.13.
1.) The source \\gisfile\GISmaps\GISstaff\Jared\Hydro.gdb, as seen in the screenshot, is what I want to replace.
As a stand-alone script, this does not change anything in the Map. However, it runs with no errors and both print statements print what they're supposed to.
for lyr in arcpy.mapping.ListLayers(mxd):
if str(lyr.name) == "Test":
lyr.replaceDataSource(r"\\gisfile\GISstaff\Jared\Hydro.gdb", "FILEGDB_WORKSPACE", "Hydro_WillCounty_Waterways")
print lyr.dataSource
mxd.save()
del mxd
print "+++ Gut +++"
\\gisfile\GISstaff\Jared\Hydro.gdb\Hydro_WillCounty_Waterways
+++ Gut +++
2.) Same thing in IDLE Python 2.7.13. It runs with no errors and both print statements print. But, nothing happens in the map.
3.) If I run the same script in the ArcMap Python pane it will work.
import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
for lyr in arcpy.mapping.ListLayers(mxd):
if str(lyr.name) == "Test":
lyr.replaceDataSource(r"\\gisfile\GISstaff\Jared\Hydro.gdb", "FILEGDB_WORKSPACE", "Hydro_WillCounty_Waterways")
print lyr.dataSource
mxd.save()
del mxd
print "+++ Gut +++"
I'm going to try and have PyScripter point to Python 3.x. I wanted to check here to see if anyone has seen this before.