ArcPy Traceback(最近一次调用最后一次):错误

时间:2015-12-18 14:45:00

标签: python arcpy traceback

我使用模型构建器将地理数据库中的要素类转换为shapefile到预先存在的文件夹中。它运行成功。但是,当我将Model导出到Python脚本并在Python中运行时,我收到一条错误消息:

追踪(最近一次通话):   文件“C:\ Users \ Mark.Novicio \ Desktop \ New folder \ FSA_Counties_delivered_by_GISO \ Updated_Iterators.py”,第13行,in     arcpy.ImportToolbox(“模型函数”)

python脚本附在图片中:

enter image description here

1 个答案:

答案 0 :(得分:2)

从模型构建器导出的ArcPy代码通常需要进行大量调整,尽管它可能是一个适度有用的起点。

IterateFeatureClasses_mb is the python-code of a ModelBuilder only tool.

  

此工具适用于ModelBuilder,而不适用于Python脚本。

由于您希望使用Python,因此需要使用普通迭代器(通常是运行在要素类列表中的for循环)。您可以自动build the list with arcpy.ListFeatureClasses,然后循环:

# set the workspace
arcpy.env.workspace = Test_gdb

# get a list of feature classes in arcpy.env.workspace
listFC = arcpy.ListFeatureClasses()

# iterate
for fc in listFC:
    #
    # code to do to fc
    #

如果您只打算使用一次要素类列表,请在ListFeatureClasses循环中调用for

for fc in arcpy.ListFeatureClasses():

在任何一种情况下,一旦循环工作,你需要look at FeatureClassToFeatureClass for outputting a shapefile:)