我一直在努力在TOC中添加图层。我设法添加了单层,但需要遍历文件夹并添加所有层。我根本无法添加Shapefile。仅图层文件。以下是我所在位置的代码:
for layer in shp_List:
mxd = arcpy.mapping.MapDocument("CURRENT")
dataFrame = arcpy.mapping.ListDataFrames(mxd, "*")[0]
outlayer = lyr
layerfile = os.path.join(base_Folder, lyr + ".lyr")
arcpy.MakeFeatureLayer_management(layer, outlayer)
arcpy.SaveToLayerFile_management(outlayer, layerfile, "ABSOLUTE")
addlayer = arcpy.mapping.Layer(layerfile)
arcpy.mapping.AddLayer(dataFrame, addlayer, "BOTTOM")
#addLayer = arcpy.mapping.Layer(layer)
#arcpy.mapping.AddLayer(dataFrame, addLayer, "BOTTOM")
#arcpy.RefreshTOC()
#arcpy.RefreshActiveView()
del addlayer, mxd
上面的代码会将每一层添加到目录中,然后将其删除,然后添加下一层。整个脚本完成后,目录中什么都没有了。我尝试将此脚本添加到模型中并创建一个派生的输出参数,然后将其作为模型参数添加,并选中“添加到显示”。我还检查了地理处理选项,以确保选中了要添加到显示的框。我正在运行Arc 10(无Service Pack)。有人可以帮忙吗?