我的代码:
# Change Feature Classes to Relative Path Lyr files
import arcpy, csv, os
from arcpy import env
env.overwriteOutput = True
mxd = arcpy.mapping.MapDocument("CURRENT")
messageStr = str(mxd)
arcpy.AddMessage(messageStr)
arcpy.env.workspace = "C:\\GeneralWorkData\\ArcGIS Test Data\\Test Data From,to Martin B\\Relative_Paths_Lyr_Files"
for fc in arcpy.mapping.ListLayers(mxd):
fc = str(fc)
out_layer = fc + ".lyr"
arcpy.SaveToLayerFile_management(fc,out_layer,"RELATIVE")
messageStr = out_layer
arcpy.AddMessage(messageStr)
这将循环当前加载数据中的所有图层名称。工作正常,直到它到达名为“Observed pipeline/cable”的层,并给出以下消息:
错误 000732:输入层:观察到的数据集管道/电缆不存在或不受支持“。执行失败(SaveToLayerFile)。”
它是否认为正斜杠是目录的一部分(它不是)?我该怎么做才能使 SaveToLayerFile() 接受正斜杠作为图层名称的一部分?