GetParameterAsText

サマリー

Gets the specified parameter as a text string by its index position or parameter name.

注意:

The GetParameterAsText function is for use with script tools (.tbx, .atbx). For a Python toolbox (.pyt) tool, access a parameter's value as a string using the Parameter object's valueAsText property.

説明

Any value regardless of the parameter data type will be returned as a string; to use the parameter as an ArcPy or Python object instead, see the GetParameter function.

構文

GetParameterAsText (index)
パラメーター説明データ タイプ
index

The index position of the parameter, or the or name of the parameter.

Integer
戻り値
データ タイプ説明
String

The parameter value returned as an object..

コードのサンプル

GetParameterAsText example

Get specified parameter as text string using the parameter's index position.

import os
import arcpy

# Set the input workspace, get the feature class name to copy
#  and the output location.
arcpy.env.workspace = arcpy.GetParameterAsText(0)
in_featureclass = arcpy.GetParameterAsText(1)
out_workspace = arcpy.GetParameterAsText(2)

out_featureclass = os.path.join(out_workspace,
                                os.path.basename(in_featureclass))

# Copy feature class to output location
arcpy.management.CopyFeatures(in_featureclass, out_featureclass)
GetParameterAsText example

Get specified parameter as text string using the parameter's name. The script tool accepts three parameters, workspace, in_featureclass, and out_workspace.

import os
import arcpy

# Set the input workspace, get the feature class name to copy
#  and the output location.
arcpy.env.workspace = arcpy.GetParameterAsText("workspace")
in_featureclass = arcpy.GetParameterAsText("in_featureclass")
out_workspace = arcpy.GetParameterAsText("out_workspace")

out_featureclass = os.path.join(out_workspace,
                                os.path.basename(in_featureclass))

# Copy feature class to output location
arcpy.management.CopyFeatures(in_featureclass, out_featureclass)

関連トピック