GetParameter

Resumen

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

Nota:

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.

Debate

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

Sintaxis

GetParameter (index)
ParámetroExplicaciónTipo de datos
index

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

Integer
Valor de retorno
Tipo de datosExplicación
Parameter

The parameter value returned as an object.

Muestra de código

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

Temas relacionados