GetParameterAsText

Resumen

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

Nota:

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.

Debate

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.

Sintaxis

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

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

Integer
Valor de retorno
Tipo de datosExplicación
String

The parameter value returned as an object..

Muestra de código

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)

Temas relacionados