如何使用arcpy更改文件夹X中每个图层文件的源数据路径?
我已尽可能地使用arcpy.mapping来更新和修复数据源,但是得到的却是无济于事的Runtime error <type 'exceptions.ValueError'>: Layer: Unexpected error
,它不能告诉我足够的信息来解决问题或遗漏之处。
继承代码(简化为测试单层文件):
import arcpy, os
fname = r'K:\Layers\xxx.lyr'
lyr = arcpy.mapping.Layer(fname)
oldpath = lyr.workspacePath
print 'oldpath: ', oldpath
lyr.findAndReplaceWorkspacePath(oldpath, r'C:\some\other.gdb')
print 'newpath: ', lyr.workspacePath
结果:
oldpath: K:\Canvec_Utility\Temp.gdb
Traceback (most recent call last):
File "x10x.py", line 12, in <module>
lyr.findAndReplaceWorkspacePath(oldpath, r'C:\some\other.gdb')
File "C:\ESRI\ArcGIS\Desktop10.0\arcpy\arcpy\utils.py", line 181, in fn_
return fn(*args, **kw)
File "C:\ESRI\ArcGIS\Desktop10.0\arcpy\arcpy\_mapping.py", line 601, in findAndReplaceWorkspacePath
return convertArcObjectToPythonObject(self._arc_object.findAndReplaceWorkspacePath(*gp_fixargs((find_workspace_path, replace_workspace_path, validate), True
)))
ValueError: Layer: Unexpected error
((将“更新”部分移至答案中))
Runtime error...
上面引述的是ArcCatalog中的交互式Python外壳,这并没有给回溯。带回溯的结果是从命令外壳复制的。