arcgis python 导出统计表,Exporting a model to a Python script

The option to export a model to a Python script is valuable in helping you learn how tools and environments are used in Python, and often can jumpstart your development. After editing and completing the script, it can be added to a toolbox or model as a script tool and run as any other geoprocessing tool. To export a model to a script, follow the steps below:Legacy:

Functionality to export models to JScript and VBScript has been removed from ModelBuilder at version 10.From the menu in ModelBuilder, point to and click Model > Export > To Python Script.

Click the Save in drop-down arrow and navigate to the location where you want to save your script.

Type a file name for the script.

Click Save.

Editing an exported Python script

There are instances when your exported model will not work. Take the following points under consideration when exporting a model to a script:If you expect to be overwriting data, set the arcpy.env.overwriteOutput property to True.

If your model used layers or table views that weren't created within the original model, those layers or table views will have to be created in the script using tools such as Make Feature Layer and Make Table View.

Data elements from your model are converted directly into variables in the exported script. Avoid naming data elements that will be incompatible in Python (for example, class, global, and return). For a full list of reserved keywords, use Python's keyword module.

import keyword

print keyword.kwlist

If your model used any inline variable substitution, such as %workspace%, %scratchworkspace%, %n%, %i%, or %variable name%, those will have to be substituted with the correct value.

If your model used an iterator, the iteration logic will not be exported and will have to be replaced with the looping statements in Python.

Only the first value from a list variable will be exported.

If your model used a feature set or record set, the following code will be created in the export.

Export from Model with a feature set parameter

Feature_Set = arcpy.GetParameterAsText(0)

if Feature_Set == '#' or not Feature_Set:

Feature_Set = "in_memory\\{F15C6411-0F4F-4A68-9BAC-29D6E7874669}" # provide a default value if unspecifiedThe code attempts to guard against null or invalid input by setting the Feature_Set variable to an in_memory feature class. Since the in_memory feature class will not exist at the time of execution, you need to update the path to point to a feature class which is known to exist during execution. You could also change the logic to throw an error message and stop the execution if that makes more sense for your workflow.

If your model used a Model only tool, such as Merge Branch, Collect Values, or Calculate Value, these tools will not run in Python. It is required to implement the equivalent Python functionality these tools provide. For example, you will need to use if/else logic to do branching in your script.

If your model included submodels, the contents within those submodels will not be exported. Instead, the toolbox will have to be referenced and the model tool will need to be called inside the script.

Feedback on this topic?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值