GetArgumentCount

摘要

Returns the number of arguments passed to the script.

语法

GetArgumentCount ()
返回值
数据类型说明
Integer

The number of arguments passed to the script.

代码示例

GetArgumentCount example

Check for required number of arguments to run Clip tool and handle optional argument.

# Import required modules
import arcpy
from arcpy import env
import sys

# Set workspace
env.workspace = "C:/Data/airport.gdb"

# Set local variables
in_features = arcpy.GetParameterAsText(0)
clip_features = arcpy.GetParameterAsText(1)
out_feature_class = arcpy.GetParameterAsText(2)
xy_tolerance = arcpy.GetParameterAsText(3)

# Check for required number of arguments
if arcpy.GetArgumentCount() < 3:
    print "%i %s" % (arcpy.GetParameterCount("Clip_analysis"),
                     "arguments required for Clip_analysis tool")
    sys.exit(1)

# Set variable to empty string if no argument provided.
if arcpy.GetArgumentCount() < 4:
    xy_tolerance = ""

# Execute clip tool
try:
    arcpy.Clip_analysis(in_features, clip_features,
                        out_feature_class, xy_tolerance)
except:
    print arcpy.GetMessages(2)

相关主题


7/10/2012