arcpy FindReplace Data Sources

1083
6
08-11-2021 09:11 AM
GIS_AdminCity_of_Charlottetown
New Contributor II

Using this https://desktop.arcgis.com/en/arcmap/10.3/analyze/arcpy-mapping/updatingandfixingdatasources.htm as a guide I am trying to find and replace the datasources in my mxd to enterprise gis sources but the new mxd created just has the same datasources. I tried doing a find and replace to another filegeodatabase but it still isn't doing the replace.

import arcpy
... mxd = arcpy.mapping.MapDocument(r'Z:\GIS\scratch\Workspaces_SDE\GDB.mxd')
... mxd.findAndReplaceWorkspacePaths(r'K:\Water and Sewer\Services\Services.gdb', r'Z:\GIS\scratch\20210809.gdb')
... mxd.saveACopy(r'Z:\GIS\scratch\Workspaces_SDE\SDE.mxd')
... del mxd

 

Is the issue the spaces?

Tags (3)
0 Kudos
6 Replies
CCWeedcontrol
Occasional Contributor III

You need to save it after.

 

mxd.save()
mxd.saveACopy(r"C:\Users\SMALIS\Documents\ArcGIS\pythonSwitchSourceNEW.mxd")

 

GIS_AdminCity_of_Charlottetown
New Contributor II

Yeah, I didn't copy the code over probably so you might have missed it but the save copy function is there and it does save a copy but none of the datasources are altered.

 

0 Kudos
CCWeedcontrol
Occasional Contributor III

I tested the following and it worked for me.

 

import arcpy

mxd = arcpy.mapping.MapDocument(r"C:\Temp\MxdDataSourceTest.mxd")
mxd.findAndReplaceWorkspacePaths(r"C:\Temp\BPs.gdb",r"C:\Temp\BPs_1.gdb")
mxd.saveACopy(r"C:\Temp\MxdDataSourceTest2.mxd")

print 'done'
0 Kudos
GIS_AdminCity_of_Charlottetown
New Contributor II

That is pretty much what I am doing without the print "done" at the bottom. Not sure what is happening it runs as if it worked with no errors but the datasources are unchanged. I even tried to replace something simple like "K" to "LOL" and it still didn't work (I choose LOL so it would stand out). I even put it in a try statement with an error capture and nothing.
Thoughts?

0 Kudos
JohannesBierer
Occasional Contributor III
GIS_AdminCity_of_Charlottetown
New Contributor II

That is good to know but the work around is literally doing it manually something I am trying to avoid lol. 

0 Kudos