Hello,
I can't find and replace a workspace path with the following script:
# -*- coding: cp1252 -*-
import arcpy, os
arcpy.env.overwriteOutput = True
mxd=arcpy.mapping.MapDocument(r"C:\temp_replaceDatasource\Detail.mxd")
class ReplaceDataSource(object):
def __init__(self):
self.mxd = mxd
def DataSourcesReplace(self):
for lyr in arcpy.mapping.ListLayers(self.mxd, ""):
if lyr.isServiceLayer == 1:
print lyr.name + " is a WMS Layer"
else:
print lyr.name + " X " + lyr.dataSource
newDataSource = lyr.dataSource.replace("R:\\", "\\\\{}\\{}\\".format("Client", "R$"))
print newDataSource
lyr.findAndReplaceWorkspacePath(lyr.dataSource, newDataSource)
print lyr.dataSource
mxd.saveACopy(r"C:\temp_replaceDatasource\Detail_WIBAS.mxd")
if __name__ == '__main__':
MyClass = ReplaceDataSource()
MyClass.DataSourcesReplace()
The print statement looks ok but the path is not replaced - nothing happens with the path? Any ideas why?
output of the print statement
Maßnahmenflaeche X R:\SG-A\Karto\Bierer2020\Wiedemann_Erlen_Metten_Gründelbachniederung_Auftragskarte\Bearbeitung.gdb\data\Massnahme
\\Client\R$\SG-A\Karto\Bierer2020\Wiedemann_Erlen_Metten_Gründelbachniederung_Auftragskarte\Bearbeitung.gdb\data\Massnahme
R:\SG-A\Karto\Bierer2020\Wiedemann_Erlen_Metten_Gründelbachniederung_Auftragskarte\Bearbeitung.gdb\data\Massnahme