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