.replaceDataSource - Error Message?

619
1
Jump to solution
08-27-2020 03:56 AM
JohannesBierer
Occasional Contributor III

I've problems with .replaceDataSource. I get an error message running this script?

# -*- coding: cp1252 -*-
import arcpy, os

arcpy.env.overwriteOutput = True

mxd=arcpy.mapping.MapDocument(r"R:\SG-A\Karto\Bierer2020\WIBAS_Zentralisierung\ReplaceDataSource\Detail.mxd")

# Encoding der Standardausgabe herausfinden
stdout_encoding = sys.stdout.encoding or sys.getfilesystemencoding()

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

                dataSource = lyr.dataSource.encode(stdout_encoding)

                newDataSource = dataSource.replace("R:\\", "\\\\Client\\R$\\""")
                newDataSource1 = (os.path.dirname(newDataSource))
                print newDataSource1

                lyr.replaceDataSource(workspace_path = newDataSource1, workspace_type = "FILEGDB_WORKSPACE", dataset_name = lyr.name)
            
        mxd.saveACopy(r"R:\SG-A\Karto\Bierer2020\WIBAS_Zentralisierung\ReplaceDataSource\Detail_WIBAS.mxd")
       
                         
if __name__ == '__main__':

    MyClass = ReplaceDataSource()
    MyClass.DataSourcesReplace()
    ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Error Message:

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

Traceback (most recent call last):
 ... line 36, in DataSourcesReplace
    lyr.replaceDataSource(workspace_path = newDataSource1, workspace_type = "FILEGDB_WORKSPACE", dataset_name = lyr.name)
  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\_mapping.py", line 681, in replaceDataSource
    return convertArcObjectToPythonObject(self._arc_object.replaceDataSource(*gp_fixargs((workspace_path, workspace_type, dataset_name, validate), True)))
ValueError: Layer: Unexpected error

0 Kudos
1 Solution

Accepted Solutions
JohannesBierer
Occasional Contributor III

sorry wrong command - i wanted to do .findAndReplaceWorkspacePath

View solution in original post

0 Kudos
1 Reply
JohannesBierer
Occasional Contributor III

sorry wrong command - i wanted to do .findAndReplaceWorkspacePath

0 Kudos