ESRI 10.5
I have an MXD file with a single layer pointing to an SDE Feature class and I want to point to an SDE Feature class with a different name
C:\Temp\jc_mxd\AppsInternal\simple.mxd
Layer name =SDI.MTD.LAYER
dataSource =c:\temp\SDI.sde\SDI.MTD.LAYER
Name :SDI.MTD.LAYER
baseName :SDI.MTD.LAYER
CatalogPath :C:\Temp\SDI.sde\SDI.MTD.LAYER
dataElementType:DEFeatureClass
DataType :FeatureClass
extension :
file :SDI.MTD.LAYER
path :C:\Temp\SDI.sde
Traceback (most recent call last):
File "mxd5.py", line 22, in <module>
lyr.replaceDataSource ("c:\temp\SDI.sde","SDE_WORKSPACE","MTD.NEW" )
File "D:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy\arcpy\utils.py", line 182, in fn_
return fn(*args, **kw)
File "D:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy\arcpy\_mapping.py", line 682, in replaceDataSource
return convertArcObjectToPythonObject(self._arc_object.replaceDataSource(*gp_fixargs((workspace_path, workspace_type, dataset_name, validate), True)))
ValueError: Layer: Unexpected error
Source code:
import arcpy,os
conn_Input = r"C:\Temp\SDI.sde"
arcpy.env.workspace = conn_Input
inmxd = r"C:\Temp\jc_mxd\AppsInternal\simple.mxd"
mxd = arcpy.mapping.MapDocument(inmxd)
for lyr in arcpy.mapping.ListLayers(mxd):
if lyr.supports("DATASOURCE"):
dataSource = lyr.dataSource
print inmxd
print "Layer name =" + lyr.name
print "dataSource =" + lyr.dataSource
desc = arcpy.Describe(lyr.name)
print("Name :" + desc.name)
print("baseName :" + desc.baseName)
print("CatalogPath :" + desc.catalogPath)
print("dataElementType:" + desc.dataElementType)
print("DataType :" + desc.dataType)
print("extension :" + desc.extension)
print("file :" + desc.file)
print("path :" + desc.path)
lyr.replaceDataSource ("c:\temp\SDI.sde","SDE_WORKSPACE","MTD.NEW" )
del mxd
Solved! Go to Solution.
OK, I found it !!
lyr.replaceDataSource ("c:\temp\SDI.sde","SDE_WORKSPACE","MTD.NEW" )
should have been
lyr.replaceDataSource ("c:\\temp\\SDI.sde","SDE_WORKSPACE","MTD.NEW" )
Stupid mistake, not helped by vague error message
OK, I found it !!
lyr.replaceDataSource ("c:\temp\SDI.sde","SDE_WORKSPACE","MTD.NEW" )
should have been
lyr.replaceDataSource ("c:\\temp\\SDI.sde","SDE_WORKSPACE","MTD.NEW" )
Stupid mistake, not helped by vague error message