GetParameter

Zusammenfassung

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

Hinweis:

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.

Diskussion

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

Syntax

GetParameter (index)
ParameterErläuterungDatentyp
index

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

Integer
Rückgabewert
DatentypErläuterung
Parameter

The parameter value returned as an object.

Codebeispiel

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}")

Verwandte Themen