GetParameter

サマリー

From the parameter list, select the desired parameter by its index or its name. The parameter is returned as an object.

注意:

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

説明

To use the parameter as a text string instead, see the GetParameterAsText function.

構文

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

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

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

The parameter value returned as an object.

コードのサンプル

GetParameter example 1

Get a script tool parameter as an object. The script tool has one parameter that accepts a spatial reference object. The parameter is selected by its index.

import arcpy

# Get the spatial reference from the tool dialog.
spatial_ref = arcpy.GetParameter(0)

# Display the Spatial Reference properties
arcpy.AddMessage("Name is: {0}".format(spatial_ref.name))
arcpy.AddMessage("Type is: {0}".format(spatial_ref.type))
arcpy.AddMessage("Factory code is: {0}".format(spatial_ref.factoryCode))
GetParameter example 2

Get a script tool parameter as an object. The script tool has one parameter named in_spatial_reference, that accepts a spatial reference object. The parameter is selected by its name.

import arcpy

# Get the spatial reference from the tool dialog.
spatial_ref = arcpy.GetParameter("in_spatial_reference")

# Display the Spatial Reference properties
arcpy.AddMessage(f"Name is: {spatial_ref.name}")
arcpy.AddMessage(f"Type is: {spatial_ref.type}")
arcpy.AddMessage(f"Factory code is: {spatial_ref.factoryCode}")

関連トピック