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
Solved! Go to Solution.
You are using arcmap 10.4.... there are lots of bugs noted on the tech support site, that you may want to look at for example
but there are more
findAndReplaceWorkspacePath issues ... sort newest to oldest
Thank you David,
unfortunately I get an error message if I insert lyr.save() after the findAndReplace ... :
line 35, in DataSourcesReplace
lyr.save()
File "C:\Program Files (x86)\ArcGIS\Desktop10.4\ArcPy\arcpy\utils.py", line 182, in fn_
return fn(*args, **kw)
File "C:\Program Files (x86)\ArcGIS\Desktop10.4\ArcPy\arcpy\arcobjects\mixins.py", line 416, in save
assert hasattr(self, '_lyr'), gp.getIDMessage(89003, "No filename set.")
AssertionError: No filename set.
You are using arcmap 10.4.... there are lots of bugs noted on the tech support site, that you may want to look at for example
but there are more
findAndReplaceWorkspacePath issues ... sort newest to oldest